Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Saving GridSplitter position

Tags:

wpf

I have this:

        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="50*" />
            <ColumnDefinition Width="5" />
            <ColumnDefinition Width="50*" />
        </Grid.ColumnDefinitions>
        <GridSplitter Background="{x:Static SystemColors.ControlBrush}"
          Grid.Column="1"
          Margin="0,0,0,0"
          Name="splitter"
          HorizontalAlignment="Stretch" />

I'm trying to save and restore the splitter position. I'm using grid.ColumnDefinitions[0].Width, which returns the width of the column in pixels.

When I restore the position, how do I restore AND keep the 50* setting, so that when you resize the window, the column resizes correctly?

like image 707
dan gibson Avatar asked Sep 27 '10 08:09

dan gibson


1 Answers

The Width property is not a simple double, it is a System.Windows.GridLength object which contains the Value property (double) and a GridUnitType property (GridUnitType) which is an enum. So, to set your column's width to 50*:

grid.ColumnDefinitions[0].Width = new GridLength(50, GridUnitType.Star)

To save and restore all you need to do is to save the value and the GridUnitType for each column.

Hope it helps.

like image 124
Captain Avatar answered Nov 05 '22 12:11

Captain