开发者

Databinding ContextMenu MenuItems to an existing Menu's MenuItems

Given a menu named "main", I want to write markup like the following:

<Window.ContextMenu>
    <ContextMenu ItemsSource="{Binding ElementName=main, Path=Items}" />
</Window.ContextMenu>

This doesn't work - it seems to create an empty ContextMenu.

This is the markup for the Menu:

<Menu Name="main" Grid.ColumnSpan="2" FontSize="14" DockPanel.Dock="Top" HorizontalAlignment="Stretch">
    <MenuItem Header="_File">
        <MenuItem Header="_Exit" Command="Close" />
    </MenuItem>
    <MenuItem Header="_Options">
        <MenuItem Header="_S开发者_StackOverflow中文版how status bar" IsCheckable="True" />
        <MenuItem Header="_Group numbers" IsCheckable="True" />
    </MenuItem>
<MenuItem Header="_About" />


The solution here is sufficient for my needs, even though it doesn't use databinding, but an array of menuitems as a resource.

It would still be interesting theoretically to know if this is possible somehow.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜