2

私は辞書を持っています

public class TAGs :INotifyPropertyChanged{
private Dictionary<string, string[]> _items = new Dictionary<string,string[]>();
 ...............
public string[] Keys
    {
        get { return Items.Keys.ToArray(); }
    }

}

キー用の 1 つのリストと、選択したキーの値を含むもう 1 つのリストの 2 つのリストを作成したいのですが、これを試してみましたが、うまくいきません

<ListBox x:Name="TagNameList" ItemsSource="{Binding Keys}"/>
<ListBox ItemsSource="{Binding Items[{Binding SelectedItem,ElementName=TagNameList}]}"/>

私はそれらをグリッドに含め、それらのデータコンテキストはタグのオブジェクトです。最初のリストボックスはプロパティへの単純なバインドとして正常に機能していますが、2 番目のリストは役に立ちませんか?

4

1 に答える 1

0

"{Binding Items[{Binding SelectedItem,ElementName=TagNameList}]}"有効な xaml ではありません。パスはコンパイル時に構築されるため、パス内でバインディングを行うことはできません。

私自身がこれに遭遇したとき、私は単純に何か他のものを1つにバインドしSelectedItemListBoxしまい、それが変更の通知を受け取ったときに、2番目がバインドされているNotifyPropertyChanged別のプロパティを公開しています。Items[selectedKey]ListBox

xaml:

<ListBox x:Name="TagNameList" ItemsSource="{Binding Keys}" SelectedItem={Binding Selected}/>
<ListBox ItemsSource="{Binding ValueFromKey}"/>

C#:

string _selected;
public string Selected
{
    get { return _selected; }
    set 
    { 
        _selected= value; 
        OnPropertyChanged("Selected");
        OnPropertyChanged("ValueFromKey");
    }
}

public string[] ValueFromKey
{
    get { return Items[Selected]; }
}
于 2012-12-10T21:41:35.820 に答える