1

この質問は避けましたが、ListBoxの選択されたインデックスを設定できません。他のスレッドを読んで設定を適用しましたが、機能しません。

            <ListBox  ItemsSource="{Binding}" 
                      HorizontalAlignment="Right" 
                      Name="lstReading" Height="Auto" 
                      SelectedIndex="{Binding BookmarkSelectedIndex}">

something.xaml.csでは、私は設定です

            lstReading.DataContext = IQText;

ここで、IQTextはであり、 asデータ要素IEnumerable<dictIQ>を含みます。BookmarkSelectedIndexIQTextの他のデータ要素を使用することはできますが、listindexを設定することはできません。誰かが理由を教えてもらえますか?

4

2 に答える 2

1

クラスBookmarkSelectedIndexの中にいますか?dictIQつまり、BookmarkSelectedIndexコレクションごとではなく、アイテムごとに1つあります。

BookmarkSelectedIndex外部に個別のプロパティを作成することdictIQも、継承しObservalbeCollection<dictIQ>て追加のプロパティを持つクラスを作成することもできBookmarkSelectedIndexます。

public class CollectionWithIndex: ObservalbeCollection<dictIQ>
{
    public int BookmarkSelectedIndex { get; set; }
}

私はあなたがあなたに適した最良の解決策を選ぶことを願っています

于 2012-04-10T19:19:37.343 に答える
1

実行時にアイテムを選択するためにこのコードを使用します...

List<Audio> lst = Audio.GetAudioFiles();
            Audio aufile = new Audio { FileDisplayName = "Select Audio File" };
            lst.Insert(0, aufile);
            lstPickAudio.ItemsSource = lst;
           string FileDisplayName="your condition"
            lstPickAudio.SelectedItem = lst.Where(p => p.FileName == FileDisplayName).First();
于 2012-04-11T10:51:56.883 に答える