Prism DelegateCommand 未在 SelectionChanged 上触发

Prism DelegateCommand not firing on SelectionChanged

我有以下委托命令:

视图模型

使用Prism.Mvvm; 使用 System.Collections.ObjectModel;

命名空间Photography.ViewModels { public class ApertureDataGridViewModel : BaseViewModel {

    private readonly ConnectedRepository _repo = new ConnectedRepository();

    public DelegateCommand<object> SelectionChangedCommand { get; private set; }

    public ObservableCollection<Aperture> Apertures { get; set; }

    public ApertureDataGridViewModel()
    {
        SelectionChangedCommand = new DelegateCommand<object>(SelectionChanged);

        Apertures = new ObservableCollection<Aperture>(_repo.GetApertures());
    }
   
    public void SelectionChanged(object param)
    {
        if (param == null)
        return;
     }

查看

 <UserControl x:Class="Photography.Views.ApertureDataGridView"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
             xmlns:vw="clr-namespace:Photography.Views"
             xmlns:prism="http://prismlibrary.com/"
             prism:ViewModelLocator.AutoWireViewModel="True">
    <Grid>
        <Grid.Resources>
            <vw:TableEditWindow x:Key="TableEditWindow"/>
        </Grid.Resources>
        <Grid.ColumnDefinitions>
            <ColumnDefinition/>
        </Grid.ColumnDefinitions>
        <Grid.RowDefinitions>
            <RowDefinition/>
        </Grid.RowDefinitions>
        <DataGrid x:Name="DataGridEdit"
                  AreRowDetailsFrozen="True"
                  AutoGenerateColumns="False"
                  Grid.Column="0"
                  Grid.Row="0"
                  DisplayMemberPath="{Binding ApertureName}"
                  IsReadOnly="False"
                  ItemsSource="{Binding Apertures}"                  
                  SelectionMode="Single"
                  SelectionUnit="FullRow"
                  Style="{DynamicResource SelectorDataGrid}"
                  VerticalAlignment="Top"
                  VerticalScrollBarVisibility="Auto">
            <DataGrid.CellStyle>
                <Style TargetType="{x:Type DataGridCell}">
                    <Style.Triggers>
                        <Trigger Property="DataGridCell.IsSelected" Value="True">
                            <Setter Property="Background" Value="{DynamicResource DatagridRowSelected}" />
                        </Trigger>
                    </Style.Triggers>
                </Style>
            </DataGrid.CellStyle>
            <i:Interaction.Triggers>
                <i:EventTrigger EventName="SelectionChanged">
                    <prism:InvokeCommandAction Command="{Binding SelectionChangedCommand}"
                                               CommandParameter="{Binding SelectedItem,
                                               ElementName=DataGridEdit}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
            <DataGrid.Resources>
            <Style TargetType="DataGridColumnHeader">
                <Setter Property="Background" Value="{StaticResource MainBackgroundColor}"/>
                <Setter Property="BorderBrush" Value="{DynamicResource MainForegroundColor}"/>
                <Setter Property="BorderThickness" Value="1"/>
                <Setter Property="Foreground" Value="{DynamicResource MainForegroundColor}"/>
                <Setter Property="HorizontalContentAlignment" Value="Center"/>
            </Style>
        </DataGrid.Resources>
            <DataGrid.Columns>
                <DataGridTextColumn Binding="{Binding ApertureId}" Visibility="Hidden"/>
                <DataGridTextColumn Binding="{Binding ApertureName}" Header="Name" Width="10*"/>
                <DataGridCheckBoxColumn Binding="{Binding Active}" Header="Active" Width="3*"/>
                <DataGridTextColumn Binding="{Binding Notes}" Header="Notes" Width="10*"/>
            </DataGrid.Columns>
            <DataGrid.RowDetailsTemplate>
                <DataTemplate>
                    <DockPanel LastChildFill="False" Margin="5 5 5 5 ">
                        <Grid>
                            <Grid.ColumnDefinitions>
                                <ColumnDefinition Width="1*"/>
                                <ColumnDefinition Width="2*"/>
                            </Grid.ColumnDefinitions>
                            <Grid.RowDefinitions>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height="auto"/>
                                <RowDefinition Height=" auto"/>
                            </Grid.RowDefinitions>
                            <Label Grid.Column="0" Grid.Row="0" Content="Name: " Style="{DynamicResource LabelExpandedRow}"/>
                            <TextBlock Grid.Column="1" Grid.Row="0" Text="{Binding ApertureName}" VerticalAlignment="Center"/>
                            <Label Grid.Column="0" Grid.Row="1" Content="Active: " Style="{DynamicResource LabelExpandedRow}"/>
                            <TextBlock Grid.Column="1" Grid.Row="1" Text="{Binding Active}" VerticalAlignment="Center"/>
                            <Label Grid.Column="0" Grid.Row="2" Content="Notes: " Style="{DynamicResource LabelExpandedRow}"/>
                            <TextBox Grid.Column="1" Grid.Row="2" Text="{Binding Notes}" Style="{StaticResource TextBoxExpandedRow}"/>
                        </Grid>
                    </DockPanel>
                </DataTemplate>
            </DataGrid.RowDetailsTemplate>
        </DataGrid>
    </Grid>
</UserControl>

调用Window视图

 <!--row 2-->
        <ContentControl
                Grid.Column="0"
                Grid.ColumnSpan="3"
                Grid.Row="2"
                Margin="10 10 10 10"
                Visibility="{Binding ViewVisible, 
                    Converter={StaticResource ControlViewVisibleConverter},
                    ConverterParameter=Aperture}">
                <vw:ApertureDataGridView Visibility="Visible"/>
        </ContentControl>

我在应用程序的不同部分使用了完全相同的代码。谁能找出我做错了什么?

令人难以置信的是,调试停止不起作用。将它移动到新位置后,我发现 DelegateCommand 正在运行。以前从未经历过这种情况。 谢谢大家回复。