GridSplitter Hide Column #6773
-
I have xaml like this: <DockPanel>
<CheckBox x:Name="Hide"
DockPanel.Dock="Top"/>
<Grid RowDefinitions="*" ColumnDefinitions="*,Auto,Auto">
<Border Background="CadetBlue"
Grid.Column="0">
</Border>
<GridSplitter Grid.Column="1" ResizeDirection="Columns"
IsVisible="{Binding !#Hide.IsChecked}"
Width="1"
Background="Black"/>
<TextBlock Text="My Very Very Very Very Long Content"
IsVisible="{Binding !#Hide.IsChecked}"
TextWrapping="Wrap"
Background="Red"
Foreground="White"
Grid.Column="2"/>
</Grid>
</DockPanel> When I check Hide CheckBox the grid behaves as I expected, but if I resize it with the GridSplitter before hiding, the space of column don't be reclaimed. What's my mistake? |
Beta Was this translation helpful? Give feedback.
Answered by
workgroupengineering
Oct 21, 2021
Replies: 2 comments 1 reply
-
It seems the GridSplitter sets the |
Beta Was this translation helpful? Give feedback.
1 reply
-
I have resolved. I create this Behavior namespace Grid_IsVisible_Issue.Behaviors
{
static class ColumnDefinition
{
private readonly static Avalonia.Controls.GridLength ZeroWidth =
new Avalonia.Controls.GridLength(0,Avalonia.Controls.GridUnitType.Pixel);
private readonly static AttachedProperty<Avalonia.Controls.GridLength?> LastWidthProperty =
AvaloniaProperty.RegisterAttached<Avalonia.Controls.ColumnDefinition, Avalonia.Controls.GridLength?>("LastWidth"
, typeof(ColumnDefinition)
, default );
public readonly static AttachedProperty<bool> IsVisibleProperty =
AvaloniaProperty.RegisterAttached<Avalonia.Controls.ColumnDefinition, bool>("IsVisible"
, typeof(ColumnDefinition)
, true
, coerce: ((element, visibility) =>
{
var lastWidth = element.GetValue(ColumnDefinition.LastWidthProperty);
if (visibility == true && lastWidth is { })
{
element.SetValue(Avalonia.Controls.ColumnDefinition.WidthProperty, lastWidth);
}
else if (visibility == false)
{
element.SetValue(LastWidthProperty, element.GetValue(Avalonia.Controls.ColumnDefinition.WidthProperty));
element.SetValue(Avalonia.Controls.ColumnDefinition.WidthProperty, ZeroWidth);
}
return visibility;
})
);
public static bool GetIsVisible(Avalonia.Controls.ColumnDefinition columnDefinition)
{
return columnDefinition.GetValue(IsVisibleProperty);
}
public static void SetIsVisible(Avalonia.Controls.ColumnDefinition columnDefinition, bool visibility)
{
columnDefinition.SetValue(IsVisibleProperty,visibility);
}
}
} and using like this: <Grid RowDefinitions="*">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="Auto" lb:ColumnDefinition.IsVisible="{Binding !#Hide.IsChecked}" />
</Grid.ColumnDefinitions>
<Border Background="CadetBlue"
Grid.Column="0">
</Border>
<GridSplitter Grid.Column="1" ResizeDirection="Columns"
IsVisible="{Binding !#Hide.IsChecked}"
Width="1"
Background="Black"/>
<TextBlock Text="My Very Very Very Very Long Content"
TextWrapping="Wrap"
Background="Red"
Foreground="White"
Grid.Column="2"/>
</Grid> |
Beta Was this translation helpful? Give feedback.
0 replies
Answer selected by
workgroupengineering
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I have resolved.
I create this Behavior