1

TextBlock.TextをListBox.SelectedItems.Countにバインドしたいのですが、listBoxでアイテムを複数選択すると、TextBlockに何も表示されないことがわかりました。

この方法はWPFで機能することを覚えていますが、Windowsストアアプリでは機能しなくなりました。

単純な問題を解決する別の方法はありますか?

   <StackPanel>
        <StackPanel.Resources>
            <local:NumberToTextConverter x:Key="NumToText" />
        </StackPanel.Resources>
        <TextBlock Text="{Binding SelectedItems.Count, ElementName=listBox, Mode=TwoWay, Converter={StaticResource NumToText}}"
                   Height="80" />
        <ListBox x:Name="listBox"
                 SelectionMode="Multiple" />
    </StackPanel>

これがコンバーターですが、この場合は必要ありません。

internal class NumberToTextConverter : IValueConverter
{
    public object Convert(object value, Type targetType, object parameter, string culture)
    {
        if(value != null)
            return ((int)value).ToString();

        return null;
    }

    public object ConvertBack(object value, Type targetType, object parameter, string culture)
    {
        throw new NotImplementedException();
    }

}

プログラムのエントリメインでいくつかのデータをロードします。

        List<string> gogoString = new List<string>();

        for (int i = 0; i < 4; i++)
            gogoString.Add(i.ToString());

        listBox.ItemsSource = gogoString;
4

1 に答える 1

0

わかりました、私は答えを見つけるのに遅れています。

はWPFにListBox実装されていますが、WindowsStoreアプリには実装されていません。そのため、Windowsストアアプリから、またはWindowsストアアプリでINotifyPropertyChanged通知を受け取ることができません。ListBox.Items.CountListBox.SelectedItems.Count

于 2013-01-23T08:00:21.730 に答える