Saving GridSplitter position
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"
HorizontalA开发者_Go百科lignment="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?
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.
精彩评论