.NET Core 3.1 Prism升级Interaction Trigger后SelectionChanged事件不触发
问题原因
这是http://schemas.microsoft.com/xaml/behaviors对应的官方Microsoft.Xaml.Behaviors.Wpf包的默认行为变更导致的:旧版Expression Interactivity的InvokeCommandAction不对命令参数做严格校验,无显式参数时默认传空值触发命令;新版本会在未指定参数时出现参数匹配校验失败,直接跳过命令执行。
解决方法
你可以选择以下任意一种方案修复:
方案1:显式指定空参数
如果你的命令不需要接收事件参数,给InvokeCommandAction显式声明空参数即可,修改后的触发器代码如下:
<ComboBox Name="CBGL" ItemsSource="{Binding Path=Troughs}" DisplayMemberPath="TroughNumber" SelectedValuePath="Id" SelectedValue="{Binding Model.Trough}" Width="173"> <i:Interaction.Triggers> <i:EventTrigger EventName="SelectionChanged"> <i:InvokeCommandAction Command="{Binding CBGLRegionChangedCmd}" CommandParameter="{x:Null}" /> </i:EventTrigger> </i:Interaction.Triggers> </ComboBox>
方案2:传递事件参数
如果你的命令需要接收SelectionChangedEventArgs事件参数,可以打开参数传递开关:
<i:InvokeCommandAction Command="{Binding CBGLRegionChangedCmd}" PassEventArgsToCommand="True" />
额外排查项
- 确认XAML头部的命名空间映射已经正确修改为
xmlns:i="http://schemas.microsoft.com/xaml/behaviors" - 确认项目已经完全卸载旧的
Microsoft.Expression.Interactions、System.Windows.Interactivity相关依赖,仅保留Microsoft.Xaml.Behaviors.Wpf包,避免新旧类冲突
内容的提问来源于stack exchange,提问作者freudi
相关产品推荐
相关产品推荐

