Wpf数据网格CurrentCell属性只触发一次MVVM

问题描述 投票:0回答:1

我有一个看起来像这样的数据网格:

<DataGrid x:Name="Applications" CanUserResizeColumns="False" CanUserResizeRows="False"  
 AutoGenerateColumns="false" CanUserAddRows="false" ItemsSource="{Binding Applications}" 
 SelectionMode="Single"
 CurrentCell="{Binding CellInfo, Mode=TwoWay}">

我有一个关于Current Cell的问题,它在视图模型中的属性看起来像:

    private DataGridCellInfo cellInfo;
    public DataGridCellInfo CellInfo
    {
        get => cellInfo;
        set
        {
            cellInfo = value;
            OnPropertyChanged();

            if (cellInfo.Column.DisplayIndex == 1)
            {
                var selectedApplication = (ExtendedApplicationFile)cellInfo.Item;
                ExpandAppDetailsCommand.Execute(selectedApplication);
            }
        }
    }

它做了什么,它设置了正确的项目并将其发送到将消耗和隐藏行详细信息窗口的命令。

问题是,如果我单击一次属性设置并且它将展开,但是当我在同一单元格上第二次单击时,属性未设置且详细信息行未折叠。当我点击其他单元格并返回它时它会再次工作,但这不是我的目标。

c# wpf
1个回答
0
投票

根据评论中的信息我提出了简单的解决方案,我添加了带有事件触发器的单元格模板:

<DataGridTemplateColumn.CellTemplate>
       <DataTemplate>
             <Label Content="{Binding Name}" Width="350">
                   <i:Interaction.Triggers>
                         <i:EventTrigger EventName="MouseDown">
                                  <i:InvokeCommandAction Command="{Binding DataContext.ExpandAppDetailsCommand, RelativeSource={RelativeSource AncestorType=DataGrid}}" CommandParameter="{Binding}"/>
                          </i:EventTrigger>
                    </i:Interaction.Triggers>
                 </Label>
           </DataTemplate>                
</DataGridTemplateColumn.CellTemplate>

每次单击单元格事件触发并切换详细信息视图时使用thin。

© www.soinside.com 2019 - 2024. All rights reserved.