【问题标题】:.NET Core 3.1 after updating Interaction Trigger and Prism no SelectionChanged event was firing.NET Core 3.1 更新交互触发器和 Prism 后没有触发 SelectionChanged 事件
【发布时间】:2021-12-26 01:06:43
【问题描述】:

今天我已将所有交互触发器从 http://schemas.microsoft.com/expression/2010/interactivity 更改为 http://schemas.microsoft.com/xaml/behaviors。现在我的问题是,视图模型中没有触发 selectionChanged 事件。我的数据源是视图模型。

我的代码:

<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}" />
          </i:EventTrigger>
     </i:Interaction.Triggers>

如果有人更改了选择,CBGLRegionChangedCmd 不会触发。

来自视图模型的代码:

CBGLRegionChangedCmd = new MyICommand(InvokeCommandAction_Changed);

如果我撤消更新一切正常...

【问题讨论】:

标签: wpf prism .net-core-3.1 interaction


【解决方案1】:

您必须将 ViewModel 添加到此问题以获得最佳答案。 但我认为您在 SelectedValue="{Binding Model.Trough}" 中的绑定是错误的 请在视图模型中定义一个完整的属性,其类型为 Trough 和 xxx 名称,然后在其中调用 notifyPropertyChange() 方法,然后设置 SelectedItem="{Binding xxx,UpdateSourceTrigger=PropertyChanged}"

您还可以在 int 类型的视图模型中设置一个属性 full ,名称为 yyy 并将其绑定到 SelectedValue 属性,例如: SelectedValue="{Binding yyy,UpdateSourceTrigger=PropertyChanged}"

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-12-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2022-08-19
    相关资源
    最近更新 更多