我有一个组合框:实施中的ViewModel事件处理器与MVVM WPF
<ComboBox x:Name="cbConnection"
ItemsSource="{Binding Source={StaticResource XmlConnectionList}, XPath=//ComboItem}"
DisplayMemberPath="Key"
SelectedValuePath="Value"
SelectedValue="{Binding Path=ConnectionString,ValidatesOnDataErrors=True,UpdateSourceTrigger=PropertyChanged}"
Margin="{StaticResource ConsistentMargins}"
Validation.ErrorTemplate="{StaticResource TextBoxErrorTemplate}" Width="120"
LostFocus="{Binding Path=cbConnection_LostFocus}"/>
我试图让LostFocus事件处理程序移动到视图模型,因为我做了一些错误的引领者的SelectedValue绑定内处理“的ConnectionString “在ViewModel中找到。我希望这发生在用户重新选择相同的ComboBoxItem,这会触发OnPropertyChanged,除非选择了不同的列表项。
在错误
A“结合”以上结合导致不能在 类型“组合框”的“AddLostFocusHandler”属性被设置。 '绑定'只能在DependencyObject的DependencyProperty 上设置。
无论用户选择什么,我如何在ViewModel中选择ComboBox中的任何项目时触发可重复的代码?
+1包括ns –