对于那些纯粹使用MVVM的人,如何处理ComboBox的SelectionChanged事件而不回到代码后台?
我尝试过例如AttachedBehaviors,但是Event="SelectedChanged"不被支持:
<ComboBox>
<ComboBoxItem Content="Test1">
<c:CommandBehaviorCollection.Behaviors>
<c:BehaviorBinding Event="SelectionChanged"
Command="{Binding SelectedChanged}"
CommandParameter="MainBorder123"/>
</c:CommandBehaviorCollection.Behaviors>
</ComboBoxItem>
<ComboBoxItem Content="Test2"/>
<ComboBoxItem Content="Test3"/>
</ComboBox>
Command
,还有CallMethodAction
可用,但需要添加对Microsoft.Expression.Interactions.dll
的引用。 - markmnlComboBox
命名为"MyCombo",然后绑定是一个简单的{Binding ElementName=MyCombo, Path=SelectedItem}
。 - PaulSystem.Windows.Interactivity
后,您需要将该命名空间添加到XAML标题中:xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity"
。 - Beautyhttps://github.com/Microsoft/XamlBehaviorsWpf
。将以下内容添加到你的窗口布局 XML 文件的<Window/>
标签中:xmlns:i="http://schemas.microsoft.com/xaml/behaviors"
。更多信息请参见这里:链接。 - S0und