0

私は簡単な辞書を持っています。i をコンボボックスにバインドしてから、選択した値を別のプロパティにバインドしたいと思います。

private const string CellListPropertyName = "CellList";

    private Dictionary<string, string> _cellList;
    public Dictionary<string, string> CellsList
    {
        get { return _cellList; }
        set
        {
            _cellList = value;
            RaisePropertyChanged(CellListPropertyName);
        }
    }

これが私のコードです:

<ComboBox x:Name="comboBox"
          ItemsSource="{Binding CellsList}"
          DisplayMemberPath="Value"
          SelectedValuePath="Key" 
          SelectedValue="{Binding Path=Conf:ConfProperties.Title}">

私はさまざまな方法を試しましたが、コンボボックスは常に空です(ItemTemplatesなどを使用しても)、62個の要素が含まれている辞書を確認しました。

また、「SelectedValue」を DataContext で定義されたプロパティにバインドしようとしましたが、まだ機能しません。

これが私のコンテキストです

<UserControl.DataContext>
    <viewModel:ParametersViewModel></viewModel:ParametersViewModel>
</UserControl.DataContext>
4

1 に答える 1

0

あなたの SelectedValue バインディングは少し奇妙に見えます。ParametersViewModel に、文字列型の MySelectedTitle というプロパティがあるとします。次に、バインディングは次のようになります。

 SelectedValue="{Binding Path=MySelectedTitle}"

選択した値を現在のデータコンテキストのプロパティではなく「保存」したい場合は、質問を更新する必要があります

于 2012-06-19T13:50:02.850 に答える