I use the mvvm pattern and catel development platform . I place DataGrid on the form in the container Grid .

<catel:UserControl x:Class="WriteOffWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:catel="http://catel.codeplex.com" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:i="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity" xmlns:local="clr-namespace:Views" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"> <Grid> <DataGrid x:Name="gridDataContent" Margin="10,0,10,35" AutoGenerateColumns="False" Background="White" BorderBrush="#FFE6E6E6" CanUserAddRows="False" CanUserDeleteRows="False" FontSize="16" ItemsSource="{Binding ProductCollection}" SelectedItem="{Binding SelectedProduct}" SelectionUnit="FullRow"> <i:Interaction.Triggers> <i:EventTrigger EventName="SelectionChanged"> <catel:EventToCommand Command="{Binding Mode=TwoWay, Path=SetFocus}" PassEventArgsToCommand="True" /> </i:EventTrigger> <i:EventTrigger EventName="CellEditEnding"> <catel:EventToCommand Command="{Binding Mode=TwoWay, Path=EndEdit}" PassEventArgsToCommand="True" /> </i:EventTrigger> </i:Interaction.Triggers> <DataGrid.Resources> <Style TargetType="DataGridRow"> <Style.Resources> <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrushKey}" Opacity="0.5" Color="DodgerBlue" /> <SolidColorBrush x:Key="{x:Static SystemColors.InactiveSelectionHighlightBrush}" Color="DodgerBlue" /> </Style.Resources> </Style> </DataGrid.Resources> <DataGrid.Columns> <DataGridTextColumn Width="350" Binding="{Binding FullName}" Header="Наименование" IsReadOnly="True" /> <DataGridTextColumn Binding="{Binding Capacity}" Header="Объём" IsReadOnly="True" /> <DataGridTextColumn Binding="{Binding Quantity}" Header="Кол-во" IsReadOnly="True" /> <DataGridTextColumn Binding="{Binding WriteOffQuantity}" Header="Кол-во списываемой продукции" IsReadOnly="False" /> </DataGrid.Columns> </DataGrid> </Grid> </catel:UserControl> 

ProductCollection is of type ObservableCollection <ProductModel> .
The problem is that when I do a duplicate to change the cell, the devenv.exe process (when debugging) starts to grow in memory before the cell opens for a change, which causes VS 2015 to crash with an OutOfMemoryException error. I use the clickOnce technology, after installing the application on the PC, the application itself begins to grow in memory, the above described error occurs, or the change cell opens for a very long time.

What could be the problem? Can anyone come across?

Initialization call

 EndEdit = new Command<DataGridCellEditEndingEventArgs>(OnEndEditExecute, OnEndEditCanExecute); SetFocus = new Command<SelectionChangedEventArgs>(OnSetFocusExecute, OnSetFocusCanExecute); 

The methods themselves:

 private bool OnEndEditCanExecute(DataGridCellEditEndingEventArgs e) { if (e != null) { if (SelectedProduct != null) { var text = (TextBox)e.EditingElement; if (!string.IsNullOrEmpty(text.Text)) { text.Text = text.Text.Replace(",", ".").Replace("-", ""); if (e.Column.SortMemberPath.Equals("WriteOffQuantity")) { try { if (SelectedProduct.Quantity < Convert.ToSingle(text.Text.Replace(".",","))) { MessageBox.Show("Нельзя списать больше чем есть на остатках", "Ошибка изменения значения", MessageBoxButton.OK, MessageBoxImage.Error); text.Text = "0"; return false; } else { // text.Text = text.Text.Replace(",", "."); return true; } } catch { // text.Text = "0"; return false; } } else { return false; } } else { text.Text = "0"; return false; } } else { return false; } } else return true; } 

Here the scroll scrolls to the selected object.

 private bool OnSetFocusCanExecute(SelectionChangedEventArgs e) { if (e == null) return true; var grid = e.Source as DataGrid; if (SelectedProduct != null) { grid?.ScrollIntoView(SelectedProduct); } return true; } private void OnEndEditExecute(DataGridCellEditEndingEventArgs e) { } private void OnSetFocusExecute(SelectionChangedEventArgs e) { } 

Forgot to add, records about 1000.

  • Code commands SetFocus and EndEdit can add? - Monk
  • added to the question itself. He also sinned on them, but if you remove them, nothing changes either. - Boris Vladimirovich
  • one
    Disabling OnEndEditCanExecute not helping? He is suspicious of you. - Monk
  • No, it does not help. - Boris Vladimirovich
  • Somewhere you may not obviously looping - Alexsandr Ter

0