开发者

ContextMenu in WPF is too wide

I've got a problem with my ContextMenu in WPF. The menu is far too wide- it's the width of the items I put on it, plus about fifty-a hundred pixels. So when you open the menu, instead of being a clean list of options or buttons, there's loads of greyspace on each side. How can I fix this?

Edit: Here's my XAML for the menu:

<ContextMenu Padding="0">
    <Button Content="Close Tab" Height="23" Name="closetabbutton" Width="75" Margin="0,0,0,0" Click="closetabbutton_Click" />
    <TextBox Height="23" Name="renamebox" Width="75" HorizontalAlignment="Stretch" V开发者_如何学PythonerticalAlignment="Stretch" ClipToBounds="True" TextChanged="renamebox_TextChanged" />
    <Button Content="Close Menu" Height="23" Name="closemenubutton" Width="75" Margin="0,0,0,0" Click="closemenubutton_Click" />
</ContextMenu>


The space is reserved for icons on the left, and input gesture text (e.g. Ctrl+C) on the right. This is by design.

If you wish to change this, you'll have to create your own ContextMenu style. Here's an example of how to do this:

http://www.dev102.com/2008/06/20/how-to-create-a-wpf-custom-context-menu/

Update

Further to my question comment, MenuItems would normally be used where you have used buttons. For example:

<Grid.ContextMenu>
    <ContextMenu>
        <MenuItem Name="mnuClose" Header="Close tab" InputGestureText="Ctrl+C" />
        <MenuItem Name="mnuRename">
            <MenuItem.Header>
                <TextBox Name="txtRename" Width="100" />
            </MenuItem.Header>
        </MenuItem>
    </ContextMenu>
</Grid.ContextMenu>
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜