question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Resizeable and Collapsable sidebar with GridSplitter

See original GitHub issue

Hi! I’m trying to make a resizeable and collapsable sidebar.

I expect it to have the following behaviour:

  1. A user can resize the sidebar up and down to a particular boundary (i.e. set Min and Max width).
  2. A user can entirely hide (and then show) the sidebar

I use Grid with three columns: one for the sidebar, the second for the GridSplitter to accomplish resize and the third for the main content.

If I configure the Grid like this:

<Grid.ColumnDefinitions>
    <ColumnDefinition Width="Auto" />
    <ColumnDefinition Width="Auto" />
    <ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

I can successfully resize the sidebar and hide it with IsVisible="True" but it does not have Min Width. If I set MinWidth for the sidebar control

<Panel Grid.Column="0" MinWidth="100" />

I can still resize the leftmost column to the size less than it’s content MinWidth.

If I set MinWidth for a Grid Column:

<ColumnDefinition Width="Auto" MinWidth="100" />

The splitter lets me resize the column down to this MinWidth (just like I need), however, when I hide the sidebar with IsVisible="False" the column persists (i.e. blank space with MinWidth is shown).

The splitter is very thin and it is not an option to resize the column to width 0 and consider this as “collapsed” since there is no way to resize it back.

I’m using Avalonia 0.10.0-rc1

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:6 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
cezarypiatekcommented, Apr 13, 2023

I solved that issue by applying one of two classes that change the Grid.ColumnSpan attribute and toggling visibility of GridSplitter and Sidebar container:

<Panel>
  <Panel.Styles>
    <Style Selector=".sidebar_open">
      <Setter Property="Grid.ColumnSpan" Value="1"></Setter>
    </Style>
    <Style Selector=".sidebar_close">
      <Setter Property="Grid.ColumnSpan" Value="3"></Setter>
    </Style>
  </Panel.Styles>

  <Grid ColumnDefinitions="*,Auto, 420">
    <Panel Grid.Column="0"
      Classes.sidebar_open="{Binding IsSidebarOpen}"
      Classes.sidebar_close="{Binding !IsSidebarOpen}">
    </Panel>
    <GridSplitter Grid.Column="1" Width="3" MinWidth="1" BorderThickness="0"
      VerticalAlignment="Stretch"
      IsVisible="{Binding IsSidebarOpen}"></GridSplitter>
    <Panel Grid.Column="1" IsVisible="{Binding IsSidebarOpen}">
      <TextBlock>This is the sidebar</TextBlock>
    </Panel>
  </Grid>
  
</Panel>

1reaction
maxkatz6commented, Aug 26, 2022

SplitView has similar behavior out of box, but without grid splitter

Read more comments on GitHub >

github_iconTop Results From Across the Web

c# - Resizable and collabsable gridColumn with gridSplitter
When I use it without the GridSplitter it is working fine (except the resizing): When I press the ToggleButton the content of the...
Read more >
How to: Resize Columns with a GridSplitter - WPF .NET ...
The following example shows how to define a vertical GridSplitter that occupies a column and resizes the columns on either side of it....
Read more >
WPF GridSplitter | Advanced Splitter Control
WPF GridSplitter is a divider that splits the available space horizontally or vertically. It allows user to resize the grid's column width and...
Read more >
GridSplitter - 2000 Things You Should Know About WPF
We can verify that the columns are sized proportionally by resizing the entire Grid (containing window). The columns retain their post- ...
Read more >
The GridSplitter
Learn how to allow your end-users to resize the cells of your WPF Grid using the GridSplitter control in this article.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found