protected override void PrepareContainer(DataGridContext dataGridContext, object item) { if (this.DataContext is INotifyPropertyChanged oldRow) { oldRow.PropertyChanged -= DataRowView_PropertyChanged; } if (item is ICustomTypeDescriptor descriptor) { this.diffFields = new HashSet <string>(DiffUtility.GetDiffFields(item)); } else { this.diffFields = null; } if (item is INotifyPropertyChanged newRow) { newRow.PropertyChanged += DataRowView_PropertyChanged; } this.SetValue(DiffStatePropertyKey, DiffUtility.GetDiffState(item)); this.PropertyChanged -= DiffDataContainer_PropertyChanged; dataGridContext.DataGridControl.SelectionChanged -= DataGridControl_SelectionChanged; base.PrepareContainer(dataGridContext, item); this.SetSelectionProperty(); dataGridContext.DataGridControl.SelectionChanged += DataGridControl_SelectionChanged; this.PropertyChanged += DiffDataContainer_PropertyChanged; }
private void DataRowView_PropertyChanged(object sender, PropertyChangedEventArgs e) { if (this.DataContext == null) { return; } if (e.PropertyName == DiffUtility.DiffFieldsKey || e.PropertyName == string.Empty) { this.diffFields = new HashSet <string>(DiffUtility.GetDiffFields(this.DataContext)); } if (e.PropertyName == DiffUtility.DiffStateKey || e.PropertyName == DiffUtility.DiffEnabledKey || e.PropertyName == string.Empty) { this.SetValue(DiffStatePropertyKey, DiffUtility.GetDiffState(this.DataContext)); } if (e.PropertyName == CremaSchema.Index) { this.Dispatcher.InvokeAsync(this.SetSelectionProperty); } if (e.PropertyName == string.Empty) { if (sender is IDataErrorInfo errorInfo) { if (errorInfo.Error == string.Empty && this.HasValidationError == true) { this.Dispatcher.InvokeAsync(() => { this.EndEditCore(); }); } } } this.RefreshError(); }
private void ResetHorizontalMinimap(Grid grid, DataGridContext gridContext) { if (gridContext.VisibleColumns.Any() == false || gridContext.CurrentItem == null) { grid.Visibility = Visibility.Hidden; return; } var diffState = DiffUtility.GetDiffState(gridContext.CurrentItem); var fixedCount = (int)gridContext.GetValue(TableView.FixedColumnCountProperty); var prevState = (int)DiffState.Unchanged; var count = (double)0; var list = new List <double>(); var states = new List <int>(); var fields = DiffUtility.GetDiffFields(gridContext.CurrentItem); var totalWidth = (double)0; var fixedSize = (double)0; foreach (var item in gridContext.VisibleColumns) { var rowState = (int)diffState; if (rowState == (int)DiffState.Modified) { rowState = fields.Contains(item.FieldName) == true ? (int)DiffState.Modified : (int)DiffState.Unchanged; } if (gridContext.CurrentItem is IDataErrorInfo errorInfo && errorInfo[item.FieldName] != string.Empty) { rowState |= (1 << 16); } if (item.Index < fixedCount) { fixedSize += item.ActualWidth; } if (rowState != prevState) { if (count != 0) { list.Add(count); states.Add(prevState); } count = 0; prevState = rowState; } else { } count += item.ActualWidth; totalWidth += item.ActualWidth; } list.Add(count); states.Add(prevState); grid.Children.Clear(); grid.ColumnDefinitions.Clear(); for (var i = 0; i < list.Count; i++) { var item = list[i]; var state = states[i] & 0x0000ffff; var error = (states[i] & 0xffff0000) >> 16; var brush = DiffBrushes.GetBackgroundBrush((DiffState)state); var border = new Border() { BorderThickness = new Thickness(0, error != 0 ? 4 : 0, 0, 0), BorderBrush = Brushes.Red, Background = brush, }; Grid.SetColumn(border, grid.ColumnDefinitions.Count); grid.ColumnDefinitions.Add(new ColumnDefinition() { Width = new GridLength(item / totalWidth, GridUnitType.Star), }); grid.Children.Add(border); } grid.Visibility = Visibility.Visible; }