【发布时间】:2018-08-03 00:26:32
【问题描述】:
我正在尝试在 ComboBox DropDownClosed 上执行命令,但是在初始化该页面时运行应用程序时抛出异常:
无法添加类型的实例 'Microsoft.Xaml.Interactions.Core.EventTriggerBehavior' 到 'Microsoft.Xaml.Interactivity.BehaviorCollection' 类型的集合。
Xaml:
<ComboBox x:Name="MyCombo" FontSize="20" ItemsSource="{Binding Path=MyViewModel.MyProperty, Mode=TwoWay}"
HorizontalAlignment="Stretch" Margin="10,10,10,0" Height="56" SelectedItem="{Binding MyViewModel.MyAnotherProperty, Mode=TwoWay}">
<interactivity:Interaction.Behaviors>
<core:EventTriggerBehavior EventName="DropDownClosed">
<core:InvokeCommandAction Command="{Binding MyViewModel.MyCommand}"/>
</core:EventTriggerBehavior>
</interactivity:Interaction.Behaviors>
</ComboBox>
编辑:
我搜索了这个错误的可能原因,我发现我错过了传递元素名称
<core:EventTriggerBehavior EventName="DropDownClosed" SourceObject="{Binding ElementName=MyCombo}>
现在它抛出以下错误:
System.InvalidOperationException:添加或删除事件处理程序 WinRT 事件不支持动态。
【问题讨论】: