Using the WPF Toolkit split button to show a context menu is reasonably straight forward. Add a context menu in your window resources. On the window load - bind the context menu to the split button and then use the context menu as you would do normally.
It really needs to be added in the WPF Toolkit as the majority use case for this button is to replicate the old WinForm Splitt button.
<Window x:Class="SplitButtonTesting.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
mc:Ignorable="d"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<ContextMenu x:Key="contextMenu" IsOpen="{Binding IsOpen}">
<MenuItem Header="One" />
<MenuItem Header="Two" />
<MenuItem Header="More...">
<MenuItem Header="One" />
<MenuItem Header="Two" />
</MenuItem>
</ContextMenu>
</Window.Resources>
<DockPanel>
<Menu DockPanel.Dock="Top" x:Name="ApplicationMenu">
<xctk:SplitButton x:Name="SplitButton" Content="Main Button" DropDownContent="{x:Null}" />
</Menu>
<Border />
</DockPanel>
Code behind:
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
namespace SplitButtonTesting
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
SetupSplitButton();
}
public void SetupSplitButton()
{
var menu = this.Resources["contextMenu"] as ContextMenu;
menu.PlacementTarget = SplitButton;
menu.Placement = PlacementMode.Bottom;
menu.DataContext = SplitButton;
}
}
}