You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

.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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.26 01:36:03