简体   繁体   English

组合框数据绑定

[英]Combobox DataBinding

I'm having a problem with a combobox. 我有一个组合框问题。 I use databinding to display the content of a list (guinodes). 我使用数据绑定来显示列表(guinode)的内容。 My UINode items in the list implement INotifyPropertyChanged and raise PropertyChanged on name changes. 列表中的UINode项实现了INotifyPropertyChanged并在名称更改时引发PropertyChanged If I change the name of an item the combobox is updated, however combobox.Text remains the old value. 如果更改项目名称,则组合框会更新,但是combobox.Text仍然是旧值。 Also please note that combobox.SelectedValue.ToString() contains only the type. 还请注意, combobox.SelectedValue.ToString()仅包含类型。

Databinding looks like that : 数据绑定看起来像这样:

ItemsSource="{Binding ElementName=graphCanvas, Path=guinodes}"

your combobox SelectedValue or SelectedItem should be the selected UINode item, just take it and get the information you want from it. 您的组合框SelectedValue或SelectedItem应该是选定的UINode项,只需将其选中并从中获取所需的信息。 dont know why you use combobox.Text? 不知道为什么要使用combobox.Text?

use this: 用这个:

 <ComboBox x:Name="SubCategory"  ItemsSource="{Binding ElementName=graphCanvas, Path=guinodes}" DisplayMemberPath="SubCategoryName" SelectedValuePath="**SubCategoryID**" SelectedValue="{Binding SubCategoryID,ValidatesOnDataErrors=True,UpdateSourceTrigger=PropertyChanged}"  />

Good Luck 祝好运

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM