forked from amkovkov/GranuSightSoftware2
refactor: ResouceView
Move ResourceView and all related to ui core namespace GSS2.UI.Core Split ResourceView on separate elements Make parts folding depended on size
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
// Оригинальное решение для проблеммы сворачивания колнок в 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<GridLength?> LastWidthProperty =
|
||||
AvaloniaProperty.RegisterAttached<ColumnDefinition, GridLength?>("LastWidth", typeof(GridColumnHideBehavior), default);
|
||||
|
||||
public readonly static AttachedProperty<bool> IsVisibleProperty =
|
||||
AvaloniaProperty.RegisterAttached<ColumnDefinition, bool>("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);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user