Browse Source

fixes(DataGrid): Fix binding IsVisible

pull/6283/head
Giuseppe Lippolis 5 years ago
parent
commit
87ea2915f8
  1. 42
      src/Avalonia.Controls.DataGrid/DataGridColumn.cs

42
src/Avalonia.Controls.DataGrid/DataGridColumn.cs

@ -27,7 +27,6 @@ namespace Avalonia.Controls
private double? _minWidth;
private bool _settingWidthInternally;
private int _displayIndexWithFiller;
private bool _isVisible;
private object _header;
private DataGridColumnHeader _headerCell;
private IControl _editingElement;
@ -40,7 +39,6 @@ namespace Avalonia.Controls
/// </summary>
protected internal DataGridColumn()
{
_isVisible = true;
_displayIndexWithFiller = -1;
IsInitialDesiredWidthDetermined = false;
InheritsWidth = true;
@ -174,32 +172,42 @@ namespace Avalonia.Controls
get => _editBinding;
}
/// <summary>
/// Defines the <see cref="IsVisible"/> property.
/// </summary>
public static StyledProperty<bool> IsVisibleProperty =
Control.IsVisibleProperty.AddOwner<DataGridColumn>();
/// <summary>
/// Determines whether or not this column is visible.
/// </summary>
public bool IsVisible
{
get
{
return _isVisible;
}
set
{
if (value != IsVisible)
{
OwningGrid?.OnColumnVisibleStateChanging(this);
_isVisible = value;
get => GetValue(IsVisibleProperty);
set => SetValue(IsVisibleProperty, value);
}
if (_headerCell != null)
{
_headerCell.IsVisible = value;
}
protected override void OnPropertyChanged<T>(AvaloniaPropertyChangedEventArgs<T> change)
{
base.OnPropertyChanged(change);
OwningGrid?.OnColumnVisibleStateChanged(this);
if (change.Property == IsVisibleProperty)
{
OwningGrid?.OnColumnVisibleStateChanging(this);
var isVisible = (change as AvaloniaPropertyChangedEventArgs<bool>).NewValue.Value;
if (_headerCell != null)
{
_headerCell.IsVisible = isVisible;
}
OwningGrid?.OnColumnVisibleStateChanged(this);
NotifyPropertyChanged(change.Property.Name);
}
}
/// <summary>
/// Actual visible width after Width, MinWidth, and MaxWidth setting at the Column level and DataGrid level
/// have been taken into account

Loading…
Cancel
Save