【发布时间】:2018-10-04 16:44:06
【问题描述】:
我有一个这样的数据结构:
public Dictionary<string, string[]> AvailableFiles { get; private set; }
想一想目录及其文件的列表。我希望能够通过首先选择具有第一个ComboBox 的目录来选择文件。选择目录后,第二个ComboBox 应显示可用文件。更改第一个 ComboBox 中的选定项目应该更改第二个 ComboBox 中的项目。
这应该是可能的,但到目前为止我只做了简单的 WPF 绑定。我目前所拥有的就是这个。
<ComboBox
x:Name="CbFirmwareVersion"
ItemsSource="{Binding Path=Manager.AvailableFiles}"
SelectedIndex="0"
DisplayMemberPath="Key"
SelectedValuePath="Value"
Style="{StaticResource ComboBoxStyle}"
Margin="{StaticResource DefaultContentMargin}" />
<ComboBox
x:Name="CbFirmwareFile"
ItemsSource="{Binding Path=Manager.AvailableFiles}"
SelectedIndex="0"
DisplayMemberPath="Value"
SelectedValuePath="Key"
SelectedValue="{Binding ElementName=CbFirmwareVersion, Path=SelectedValue}"
Style="{StaticResource ComboBoxStyle}"
Margin="{StaticResource DefaultContentMargin}" />
第一个ComboBox 正确显示了目录。第二个ComboBox 将String[] Array, String[] Array.... 显示为项目而不是数组的值。
【问题讨论】:
标签: c# wpf data-binding