wpf中直接在combobox控件中输入selectedValuePath的值,显示DisplayMemberPath的值
wpf中直接在combobox控件中输入selectedValuePath的值,显示DisplayMemberPath的值,即在combobox中直接输入下列绑定的1、2、3其中一个数字,确认后显示对应的语文、数字、英语,请指教!
Window_Loaded中:
Dictionary<int, string> dicBook = new Dictionary<int, string>();
dicBook.Add(1,"语文");
dicBook.Add(2,"数学");
dicBook.Add(3,"英语");
cboBook.ItemsSource = dicBook;
xaml: 绑定如下:
<ComboBox Name="cboBook"
Height="27" Width="106" Margin="118,84,0,0"
SelectedValue="{Binding ID}"
SelectedValuePath="Key"
DisplayMemberPath="Value"
HorizontalAlignment="Left" VerticalAlignment="Top" IsEditable="False" />