如何在 WPF 中使用 cellEditEnding 或当前单元格更改事件



我是 WPF 的新手,并且收到以下错误如何重新关注这个。我想在编辑网格行并继续下一个操作而不保存网格记录后显示警告消息。如何在 MVVM 中创建事件?

严重性代码说明项目文件行抑制状态错误 CS1061 "File"不包含"cellEditEnding"的定义,并且找不到接受类型为"File"的第一个参数的扩展方法"cellEditEnding"(是否缺少 using 指令或程序集引用?

 <DataGrid   x:Name="DataGrid" utils:DataGridTextSearch.SearchValue="{Binding ElementName=txtText, Path=Text, UpdateSourceTrigger=PropertyChanged}"
                   CellEditEnding="dataGrid_CellEditEnding" ItemsSource="{Binding Path=CollectionView}" AutoGenerateColumns="False" Margin="5" SelectionMode="Single" RowStyle="{StaticResource DefaultRowStyle}"
                    SelectedItem="{Binding Path=SelectedVoice, Mode=TwoWay}" CanUserSortColumns="False" IsSynchronizedWithCurrentItem="True"
                    CanUserAddRows="False" Tag="{Binding Path=HasError,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                    CanUserResizeRows="True" >

private void dataGrid_CellEditEnding(object sender,
                                      DataGridCellEditEndingEventArgs e)
    {
        DataRowView rowView = e.Row.Item as DataRowView;
        rowBeingEdited = rowView;
    }

好吧,我已经解决了如下:

在 Xaml 中

   <DataGrid   x:Name="DataGrid" utils:DataGridTextSearch.SearchValue="{Binding ElementName=txtText, Path=Text, UpdateSourceTrigger=PropertyChanged}"
            ItemsSource="{Binding Path=CollectionView}" AutoGenerateColumns="False" Margin="5" SelectionMode="Single" RowStyle="{StaticResource DefaultRowStyle}"
                SelectedItem="{Binding Path=SelectedVoice, Mode=TwoWay}" CanUserSortColumns="False" IsSynchronizedWithCurrentItem="True"
                CanUserAddRows="False" Tag="{Binding Path=HasError,Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
                CanUserResizeRows="True" >
         <i:Interaction.Triggers>
                <i:EventTrigger EventName="CellEditEnding">
                    <i:InvokeCommandAction Command="{Binding CellEditCommand}"/>
                </i:EventTrigger>
            </i:Interaction.Triggers>
  </DataGrid>

在视图中模型.cs

    private RelayCommand cellEditingCommand;
    public ICommand CellEditCommand
    {
        get
        {
            if (cellEditingCommand == null)
            {
                cellEditingCommand = new RelayCommand(CellEdit, CanCellEdit);
            }
            return cellEditingCommand;
        }
    }
    private bool CanCellEdit(object parameter)
    {
        return true;
    }
    private void CellEdit(object parameter)
    {
        Pool.isEdit = true;
    }

相关内容

  • 没有找到相关文章

最新更新