Browse Source

DataGridCheckBoxColumn: Make IsThreeState property bindable

pull/4651/head
Maksym Katsydan 6 years ago
parent
commit
ab5c3dd190
  1. 34
      src/Avalonia.Controls.DataGrid/DataGridCheckBoxColumn.cs

34
src/Avalonia.Controls.DataGrid/DataGridCheckBoxColumn.cs

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

Loading…
Cancel
Save