开发者

Databinding ContextMenu MenuItems to an existing Menu's MenuItems

开发者 https://www.devze.com 2023-02-16 10:39 出处:网络
Given a menu named \"main\", I want to write markup like the following: <Window.ContextMenu> <ContextMenu ItemsSource=\"{Binding ElementName=main, Path=Items}\" />

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

精彩评论

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

关注公众号