我有一本简单的字典。我想将 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>