// Оригинальное решение для проблеммы сворачивания колнок в Grid от // https://github.com/AvaloniaUI/Avalonia/discussions/6773#discussioncomment-1514604 using Avalonia; using Avalonia.Controls; namespace GSS2.UI.Core.Behaviors; public static class GridColumnHideBehavior { private readonly static GridLength ZeroWidth = new GridLength(0, GridUnitType.Pixel); private readonly static AttachedProperty LastWidthProperty = AvaloniaProperty.RegisterAttached("LastWidth", typeof(GridColumnHideBehavior), default); public readonly static AttachedProperty IsVisibleProperty = AvaloniaProperty.RegisterAttached("IsVisible", typeof(GridColumnHideBehavior), true, coerce: (element, visibility) => { var lastWidth = element.GetValue(LastWidthProperty); if (visibility && lastWidth is { }) element.SetValue(ColumnDefinition.WidthProperty, lastWidth); else if (!visibility) { element.SetValue(LastWidthProperty, element.GetValue(ColumnDefinition.WidthProperty)); element.SetValue(ColumnDefinition.WidthProperty, ZeroWidth); } return visibility; } ); public static bool GetIsVisible(ColumnDefinition columnDefinition) { return columnDefinition.GetValue(IsVisibleProperty); } public static void SetIsVisible(ColumnDefinition columnDefinition, bool visibility) { columnDefinition.SetValue(IsVisibleProperty, visibility); } }