The solution is to use the menu item and decorate it.
XAML Code:
<MenuItem Click="AddPresetButton_Click" x:Name="AddPresetButton"> <MenuItem.Icon> <Image Source="/MyApp.Application;component/Resources/add.png" Height="20"/> </MenuItem.Icon> <MenuItem.Header> <StackPanel Orientation="Horizontal"> <TextBlock Text="Add Preset"/> <Image Source="/MyApp.Application;component/Resources/arrow_down_simple.png" Height="10" Margin="2,0,0,0"/> </StackPanel> </MenuItem.Header> <MenuItem.ContextMenu> <ContextMenu> <MenuItem Header="Add 1"/> <MenuItem Header="Add 2"/> <MenuItem Header="Add 3"/> </ContextMenu> </MenuItem.ContextMenu> </MenuItem>
C # code: When a menu is pressed, the context menu opens.
private void AddPresetButton_Click(object sender, RoutedEventArgs e) { var addButton = sender as FrameworkElement; if (addButton != null) { addButton.ContextMenu.IsOpen = true; } }
Joe sonderegger
source share