如何在Modern Metro UI中的wpf中添加上下文菜单

时间:2014-06-10 06:35:03

标签: wpf modern-ui

我正在使用Modern Metro UI做一个wpf应用程序,我想在这个应用程序上使用上下文菜单

我试过

 <Controls:MetroWindow x:Class="Something" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                      xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"                     
                      xmlns:Dialog="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
                      xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                      Title=""
                      Width="326.478"
                      Height="5" ShowIconOnTitleBar="True"   ShowTitleBar="True"
                      WindowStartupLocation="CenterScreen"
                      GlowBrush="{DynamicResource AccentColorBrush}"
                      mc:Ignorable="d" ResizeMode="CanMinimize" Loaded="MetroWindow_Loaded" >
    <Controls:MetroWindow.Resources>
        <ContextMenu x:Key="MyContextMenu">
            <MenuItem Header="Send" />

        </ContextMenu>

    </Controls:MetroWindow.Resources>
    <Grid>
    </Grid>
</Controls:MetroWindow>

我正在尝试将Context Menu添加到使用Modern Metro UI的Wpf应用程序

1 个答案:

答案 0 :(得分:3)

应在实际元素中声明上下文菜单:

 <Controls:MetroWindow x:Class="Something" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                  xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
                  xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"                     
                  xmlns:Dialog="clr-namespace:MahApps.Metro.Controls.Dialogs;assembly=MahApps.Metro"
                  xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
                  xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
                  Title=""
                  Width="326.478"
                  Height="5" ShowIconOnTitleBar="True"   ShowTitleBar="True"
                  WindowStartupLocation="CenterScreen"
                  GlowBrush="{DynamicResource AccentColorBrush}"
                  mc:Ignorable="d" ResizeMode="CanMinimize" Loaded="MetroWindow_Loaded" >
<Grid>
   <Grid.ContextMenu>
       <ContextMenu>
           <MenuItem Header="Send" />
       </ContextMenu>
   </Grid.ContextMenu>
</Grid>