0
A
回答
1
你会想绑定至SelectedValue
,SelectedItem
,或SelectedIndex
取决于你想要做什么:
public class MyViewModel : INotifyPropertyChanged
{
public ObservableCollection<MyObj> MyCollection { get; private set; }
private MyObj _theItem;
public MyObj TheItem
{
get { return _theItem; }
set
{
if (Equals(value, _theItem)) return;
_theItem= value;
//Or however else you implement this...
OnPropertyChanged("TheItem");
//Do something here.... OR
//This will trigger a PropertyChangedEvent if you're subscribed internally.
}
}
private string _theValue;
public string TheValue
{
get { return _theValue; }
set
{
if (Equals(value, _theValue)) return;
_theValue= value;
OnPropertyChanged("TheValue");
}
}
private int _theIndex;
public int TheIndex
{
get { return _theIndex; }
set
{
if (Equals(value, _theIndex)) return;
_theIndex = value;
OnPropertyChanged("TheIndex");
}
}
}
public class MyObj
{
public string PropA { get; set; }
}
<!-- Realistically, you'd only want to bind to one of those -->
<!-- Most likely the SelectedItem for the best usage -->
<ItemsControl ItemsSource="{Binding Path=MyCollection}"
SelectedItem="{Binding Path=TheItem}"
SelectedValue="{Binding Path=TheValue}"
SelectedIndex="{Binding Path=TheIndex}"
/>
2
绑定到SelectedItem上的属性。 在属性的setter中,执行你的功能。 的SelectedItem = “{绑定路径= SomeProperty}”
相关问题
- 1. WPF Datagrid ComboBox DataBinding
- 2. Combobox selectedvalue
- 3. Combobox DataBinding
- 4. ComboBox SelectedItem vs SelectedValue
- 5. ComboBox SelectedValue不显示
- 6. Wpf Combobox DataBinding
- 7. zk combobox databinding
- 8. Combobox SelectedValue不显示?
- 9. DataBinding Combobox值变化
- 10. 串口WPF ComboBox DataBinding
- 11. Combobox selectedvalue没有更新
- 12. Combobox SelectedValue不起作用?
- 13. Silverlight 4 Combobox与使用MVVM-Light的selectedValue
- 14. 如何在Combobox中设置Selectedvalue c#
- 15. ComboBox SelectedValue通过反射作为DependencyProperty
- 16. ComboBox SelectedValue属性不起作用
- 17. WPF combobox SelectedValue绑定到字符串
- 18. 如何使用DataBinding实现ComboBox?
- 19. Get DataGridViewComboboxColumn SelectedValue(VB.Net)
- 20. 如果将ComboBox绑定到数据集时如何显示ComboBox的SelectedValue
- 21. WInforms Combobox SelectionChangeCommitted事件并不总是改变SelectedValue
- 22. 在ComboBox中的SelectedIndex和selectedValue的愚蠢问题
- 23. 如何将ComboBox的SelectedValue绑定到属性?
- 24. C#中的DataBind - 类的ComboBox对象属性的selectedvalue
- 25. 将ComboBox的SelectedValue绑定到WPF中枚举
- 26. 无法使用DataTrigger在Combobox中设置SelectedValue
- 27. Datagrid selectedItem和databinding
- 28. TemplateSelector中的DataBinding
- 29. Devexpress如何在ComboBox DataBinding方法中获取索引行?
- 30. MVVM Databinding Datagrid与Combobox /不同项目来源