C# 将2个组合框绑定到Dict<;字符串,字符串[]>;
我有这样一个数据结构:C# 将2个组合框绑定到Dict<;字符串,字符串[]>;,c#,wpf,data-binding,C#,Wpf,Data Binding,我有这样一个数据结构: public Dictionary<string, string[]> AvailableFiles { get; private set; } 第一个组合框正确显示目录。第二个组合框将字符串[]数组、字符串[]数组..显示为项目,而不是数组的值。将第一个组合框的SelectedItem绑定到ViewModel的属性,并绑定该属性的值 <ComboBox ... SelectedItem = "{Binding Path=SelectedDirecto
public Dictionary<string, string[]> AvailableFiles { get; private set; }
第一个组合框正确显示目录。第二个
组合框
将字符串[]数组、字符串[]数组..
显示为项目,而不是数组的值。将第一个组合框的SelectedItem绑定到ViewModel的属性,并绑定该属性的值
<ComboBox
...
SelectedItem = "{Binding Path=SelectedDirectory, Mode=OneWayToSource}" />
在ViewModel中,则必须
KeyValuePair<String,String[]> SelectedDirectory {get;set;}
KeyValuePair SelectedDirectory{get;set;}
在第二个组合框中
<ComboBox
x:Name="CbFirmwareFile"
ItemsSource="{Binding Path=SelectedDirectory.Value, Mode=OneWay}"
SelectedIndex="0"
Style="{StaticResource ComboBoxStyle}"
Margin="{StaticResource DefaultContentMargin}" />
对于房地产的改变,还有一些管道工程要做。但这应该可以解决问题。谢谢。一旦SelectedDirectory的setter引发PropertyChanged事件,此操作就会生效。
<ComboBox
x:Name="CbFirmwareFile"
ItemsSource="{Binding Path=SelectedDirectory.Value, Mode=OneWay}"
SelectedIndex="0"
Style="{StaticResource ComboBoxStyle}"
Margin="{StaticResource DefaultContentMargin}" />