How to expand menu items on Mousehover in WPF MenuAdv?
The MenuItems in the WPF MenuAdv control are expanded by MouseHover, by default. You can expand the menu items on MouseClick by changing the ExpandMode property of the MenuAdv.
The following code example explains how to set the ExpandMode as ExpandonMouseover.
XAML
//Uses ExpandMode property as ExpandOnMouseOver <Window x:Class="WpfMenuAdv.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:syncfusion ="http://schemas.syncfusion.com/wpf" Title="MainWindow" Height="350" Width="525"> <Grid> <syncfusion:MenuAdv ExpandMode="ExpandOnMouseOver" > <syncfusion:MenuItemAdv Header="File"> <syncfusion:MenuItemAdv Header="New"/> <syncfusion:MenuItemAdv Header="Open"/> <syncfusion:MenuItemAdv Header="Close"/> </syncfusion:MenuItemAdv> </syncfusion:MenuAdv> </Grid> </Window>
C#
//Uses ExpandMode property namespace WpfMenuAdv { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); /// <summary> /// sets the ExpandeModes /// </summary> _menuAdv.ExpandMode = ExpandModes. ExpandOnMouseOver; MenuItemAdv _file = new MenuItemAdv() { Header = "File" }; _menuAdv.Items.Add(_file); MenuItemAdv _new = new MenuItemAdv() { Header = "New" }; MenuItemAdv _open = new MenuItemAdv() { Header = "Open" }; MenuItemAdv _close = new MenuItemAdv() { Header = "Close" }; _file.Items.Add(_new); _file.Items.Add(_open); _file.Items.Add(_close); } } }
The following code example explains how to set the ExpandMode as ExpandOnClick.
XAML
//Uses ExpandMode property as ExpandOnClick <Window x:Class="ColorPickerPallette.MainWindow" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:syncfusion ="http://schemas.syncfusion.com/wpf" Title="MainWindow" Height="350" Width="525"> <Grid> <syncfusion:MenuAdv ExpandMode="ExpandOnClick" > <syncfusion:MenuItemAdv Header="File"> <syncfusion:MenuItemAdv Header="New"/> <syncfusion:MenuItemAdv Header="Open"/> <syncfusion:MenuItemAdv Header="Close"/> </syncfusion:MenuItemAdv> </syncfusion:MenuAdv> </Grid> </Window>
C#
//Uses ExpandMode property namespace WpfMenuAdv { /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); /// <summary> /// Sets the ExpandeModes /// </summary> _menuAdv.ExpandMode = ExpandModes.ExpandOnClick; MenuItemAdv _file = new MenuItemAdv() { Header = "File" }; _menuAdv.Items.Add(_file); MenuItemAdv _new = new MenuItemAdv() { Header = "New" }; MenuItemAdv _open = new MenuItemAdv() { Header = "Open" }; MenuItemAdv _close = new MenuItemAdv() { Header = "Close" }; _file.Items.Add(_new); _file.Items.Add(_open); _file.Items.Add(_close); } } }
Conclusion
I hope you enjoyed learning how to expand menu items on Mousehover and Mouseclick in the WPF MenuAdv.
You can refer to our WPF Menu feature tour page to learn about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications. You can also explore our WPF Menu example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!