简体   繁体   中英

menu control resizing

If my window gets re-sized, the menu control re-sizes with it. And it looks very nasty when that happens. How can I prevent this? I'm looking for a property called 're size' but there isn't any.

[Edit]

<Menu Canvas.Left="0" Canvas.Top="0" Name="menu1" Margin="0,0,0,384">
    <MenuItem Header="File" StaysOpenOnClick="True" FontFamily="Arial" VerticalAlignment="Center">
        <MenuItem Click="Open_Click" IsEnabled="True">
            <MenuItem.Header>
                <TextBlock Text="Open" VerticalAlignment="Center"/>
            </MenuItem.Header>
        </MenuItem>
    </MenuItem>
    </Menu>

[/Edit]

That is because of Margin Property. Just remove it and set VerticalAlignment="Top" for Menu .

Margin="0,0,0,384" means that there are 384 units of length between Menu and bottom bound of Menu's visual parent. Thus it means that Menu height is dependent on it's visual parent height, which is dependent on window height in your case.

Specifying VerticalAlignment="Top" will lead to the following: Menu will be situated as high as possible in visual parent bounds and will have as small height as it possible to fit it's contents: "File" text in your case. If you think that's too small you can do 2 things: specify Height for Menu or, which is much more sensible, specify Padding for Menu . One would prefer specifying Padding because it will guarantee that Menu height will be enough to fit contents, no matter what FontSize or FontFamily etc. will be the MenuItem text.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM