开发者

Dynamically bound menu

开发者 https://www.devze.com 2023-03-03 01:15 出处:网络
i\'m noobie on WPF. i have this Admin menu include \'manage A\',\'manage B\',\'manage C\' in my XAML <MenuItem Header=\"_Admin\" Name=\"adminMenuItem\" Visibility=\"{Binding Path=IsAdmin, Mode=On

i'm noobie on WPF.

i have this Admin menu include 'manage A','manage B','manage C'

in my XAML

<MenuItem Header="_Admin" Name="adminMenuItem" Visibility="{Binding Path=IsAdmin, Mode=OneWay,}" >

 <MenuItem Header="manage A" Command="ShowTab" />
 <MenuItem Header="manage B" Command="ShowTab" />
 <MenuItem Header="manage C" Command="ShowTab" />            

</MenuItem>

in my mainWindow.cs code,

private void ShowTab(MenuItem menuItem)
{
    if (menuItem.开发者_如何转开发Header = "manage A")
        showTabA();
    if (menuItem.Header = "manage B")
        showTabB();
    if (menuItem.Header = "manage C")
        showTabC();
}

can i bind menuitem with commands like that? if not, what's the best way to get the value from different menu items.

Many thanks


Specify a CommandParameter in the MenuItems which identifies the tab, and get that value from the ExecutedRoutedEventArgs.Parameter property, it's cleaner than using the header at the very least.

0

精彩评论

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

关注公众号