diff --git a/src/Avalonia.Controls.DataGrid/DataGridCheckBoxColumn.cs b/src/Avalonia.Controls.DataGrid/DataGridCheckBoxColumn.cs index f1bbea9949..e2a067ac61 100644 --- a/src/Avalonia.Controls.DataGrid/DataGridCheckBoxColumn.cs +++ b/src/Avalonia.Controls.DataGrid/DataGridCheckBoxColumn.cs @@ -17,9 +17,7 @@ namespace Avalonia.Controls /// public class DataGridCheckBoxColumn : DataGridBoundColumn { - private bool _beganEditWithKeyboard; - private bool _isThreeState; private CheckBox _currentCheckBox; private DataGrid _owningGrid; @@ -31,6 +29,12 @@ namespace Avalonia.Controls BindingTarget = CheckBox.IsCheckedProperty; } + /// + /// Defines the property. + /// + public static StyledProperty IsThreeStateProperty = + CheckBox.IsThreeStateProperty.AddOwner(); + /// /// Gets or sets a value that indicates whether the hosted controls allow three states or two. /// @@ -39,17 +43,17 @@ namespace Avalonia.Controls /// public bool IsThreeState { - get - { - return _isThreeState; - } - set + get => GetValue(IsThreeStateProperty); + set => SetValue(IsThreeStateProperty, value); + } + + protected override void OnPropertyChanged(AvaloniaPropertyChangedEventArgs change) + { + base.OnPropertyChanged(change); + + if (change.Property == IsThreeStateProperty) { - if (_isThreeState != value) - { - _isThreeState = value; - NotifyPropertyChanged(nameof(IsThreeState)); - } + NotifyPropertyChanged(change.Property.Name); } } @@ -203,9 +207,9 @@ namespace Avalonia.Controls { throw new ArgumentNullException("element"); } - if(element is CheckBox checkBox) + if (element is CheckBox checkBox) { - checkBox.IsThreeState = IsThreeState; + DataGridHelper.SyncColumnProperty(this, checkBox, IsThreeStateProperty); } else { @@ -229,7 +233,7 @@ namespace Avalonia.Controls { checkBox.HorizontalAlignment = HorizontalAlignment.Center; checkBox.VerticalAlignment = VerticalAlignment.Center; - checkBox.IsThreeState = IsThreeState; + DataGridHelper.SyncColumnProperty(this, checkBox, IsThreeStateProperty); } private bool EnsureOwningGrid()