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

时间:2017-04-13 04:24:03

标签: c# wpf web-services

我是WPF的新用户,并且如果要重新启用此跟踪错误。我想在编辑网格行并继续执行下一步操作而不保存网格记录时显示警告消息。如何在MVVM中创建一个事件?

严重级代码描述项目文件行抑制状态 错误CS1061'文件'不包含' cellEditEnding'的定义没有扩展方法' cellEditEnding'接受类型'文件'的第一个参数。可以找到(你错过了使用指令或程序集引用吗?)

 <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;
    }

1 个答案:

答案 0 :(得分:1)

好吧,我已经解决了以下问题:

在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>

在ViewModel.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;
    }