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/Item
- 6. ComboBox SelectedValue不显示
- 7. GridView Combobox DataBinding WPF
- 8. Wpf Combobox DataBinding
- 9. zk combobox databinding
- 10. Combobox SelectedValue不显示?
- 11. ComboBox Event not Comming
- 12. Winforms Databinding Combobox恢复lostfocus
- 13. DataBinding Combobox值变化
- 14. 串口WPF ComboBox DataBinding
- 15. Combobox SelectedItem DataBinding NullReference异常
- 16. Combobox selectedvalue没有更新
- 17. vb.net combobox selectedvalue事件错误
- 18. Combobox SelectedValue不起作用?
- 19. 绑定ListBos ItemSource到Combobox的selectedVAlue
- 20. Kendo UI ComboBox DataSource RequestEnd event
- 21. Silverlight ComboBox SelectedValue TwoWay绑定不起作用
- 22. WPF ComboBox SelectionChanged event to command not firing
- 23. ComboBox SelectedValue通过反射作为DependencyProperty
- 24. Silverlight 4 Combobox与使用MVVM-Light的selectedValue
- 25. 如何在Combobox中设置Selectedvalue c#
- 26. WPF combobox SelectedValue绑定到字符串
- 27. ComboBox SelectedValue属性不起作用
- 28. Databinding combobox column to object(or null)in DGV
- 29. 如何使用DataBinding实现ComboBox?
- 30. Get DataGridViewComboboxColumn SelectedValue(VB.Net)