tags:

views:

151

answers:

3

I have a panel that's width can be resized during runtime

    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="770*"/>
        </Grid.ColumnDefinitions>
        <panels:NavigationPanel x:Name="cmBar" Margin="2,2,0,2" HorizontalAlignment="Left" Width="220"/>
        <panels:DetailAreaPanel x:Name="detailGrid" Margin="224,2,2,2" />
    </Grid>

When the program is closed i want to save the new width in the registry. So the program will load to the same size next time its opened. I have everything working except the width, unless i hardcode the new width. So i would assume that my save is wrong.

all[5] = cmBar.ActualWidth.ToString();

all[] is then wrote into the registry. No matter how the panel is resized cmBar.ActualWidth is always 220. Any ideas?

A: 

The little piece that says Width="220" sets the width to 220, and that will not change unless explicitly changed from the code-behind. Are you changing the panel's width in code-behind? If not - then its width really doesn't change, and stays at 220 throughout its lifetime.

Aviad P.
I took out that line and still when i resize the panel during runtime(click and drag) it does not change the width in either cmBar.Width or cmBar.ActualWidth.
K1LL3r7
I noticed when i load the width is loaded and set as `cmBar.Width = split;` So the answer seems to explain the problem, but does someone have a replacement for the code i use above. `Split` is parsed from the string array and `cmBar` should be set equal to it but i cant use `.width`
K1LL3r7
A: 

HorizontalAlignment="Stretch" will allow the control to size to its parent. "Left" just sizes to itself and leaves empty space to its right.

John Bowen
There is another panel to its right so i will need that empty space. The other panel is included ion the code above. The previous answer is correct wit the problem. ITs the .width I need another way to set the width or read the width.
K1LL3r7
To arrange multiple elements and have them resize based on available space you should try to rely on the Panel that contains them to do layout, in this case the Grid shown with additional ColumnDefinitions.Could you give some more detail on what it is that is causing the Width (that you want to save) to change. Are you expecting the internal content of the Panel to be changing size while running the application as opposed to a parent container (i.e. Window, Grid with GridSplitter)?
John Bowen
A: 

Aviad P. had one this right the .Width is what is causing the problem. The solution is is when i load the width to load it as .MaxWidth This will do the resizing but allow .ActualWidth to have the real width of the panel.

K1LL3r7