开发者

How can I get the size of a WPF panel that was changed during runtime?

I have a Panel whose 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 workin开发者_运维问答g 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?


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


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜