我使用最近发布的Windows.UI.Interactivity库将一些事件连接到WinRT应用程序中的MVVM命令。它适用于ListView,但是没有事件在组合框中触发。下面是一个ComboBox控件定义(为了清晰起见,省略了一些属性):
<ComboBox
x:Name="collectionMode"
Margin="10"
SelectedIndex="0">
<i:Interaction.Triggers>
<i:EventTrigger EventName="SelectionChanged">
<i:InvokeCommandAction Command="{Binding CollectionModeCommand}"/>
</i:EventTrigger>
</i:Interaction.Triggers>
<ComboBoxItem Content="Show collection properties" />
<ComboBoxItem Content="Show collection data" />
</ComboBox>
CollectionModeCommand永远不会被触发(我在ListView中有一个类似的布线,它工作得很好)。
已解析。问题是外部控件的不正确绑定,这当然会导致CollectionModeCommand没有绑定到ComboBox。