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)