0

I am doing one wpf app using Modern Metro UI,i want context menus on this app

as i tried

 <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>

I am trying to add Context Menu to Wpf application which uses Modern Metro UI

1 Answers1

4

A context menu should be declared within the actual element:

 <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>

eshaham
  • 869
  • 5
  • 12
  • Thanks, it's working! Can i add this context menu from code? As, if i want to set Header on Menu dynamic or depend on some conditions? – user3724710 Jun 10 '14 at 09:38
  • You can either use the [ContextMenuOpening](http://msdn.microsoft.com/en-us/library/bb613568(v=vs.110).aspx) event, or try to do databinding with the method explained [here](http://stackoverflow.com/a/15033744/3351315) – eshaham Jun 10 '14 at 10:35