Menu Split Button Example for WPF

Nevron NOV UserInterface for WPF ships with hundreds of examples with full source code, as part of the Nevron Open Vision Suite. All WPF UserInterface examples are also available as a stand-alone Visual Studio solution in C# and VB.NET, which you can download from the links below.

Menu Split Button Example for WPF Description

This example demonstrates how to create and use menu split buttons. Split buttons are drop down edits, whose item slot is filled with an action button, which generates a Click event on behalf of the split button. The menu split button's drop down content is a menu, which allows the user to quickly select an option. This option is then assigned to the action button of the split button and can be activated by clicking the action button.


Menu Split Button Example

C# Menu Split Button Example Code for Nevron UserInterface for WPF
Language: C#

using Nevron.Nov;
using Nevron.Nov.DataStructures;
using Nevron.Nov.Dom;
using Nevron.Nov.Editors;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
using Nevron.Nov.Presentation;
using Nevron.Nov.Text;
using Nevron.Nov.UI;
using Nevron.Nov.Windows.Forms;
using System.Windows.Forms;

namespace NovWinFormsProject
{
	public partial class Form1 : Form
	{
		#region Constructors

		public Form1()
		{
			InitializeComponent();

			// Set form title
			Text = "NOV WinForms - NMenuSplitButtonExample";

			// Create the NOV example and its controls
			NWidget exampleContent = CreateExampleContent();
			NWidget exampleControls = CreateExampleControls();
			if (exampleControls != null)
			{
				exampleControls.PreferredWidth = 300;
			}

			// Place the example and its controls in a pair box
			NPairBox pairBox = new NPairBox(exampleContent, exampleControls);
			pairBox.FillMode = ENStackFillMode.First;
			pairBox.FitMode = ENStackFitMode.First;
			pairBox.Margins = new NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing);

			// Host the example in the form
			NNovWidgetHost host = new NNovWidgetHost(pairBox);
			host.Dock = DockStyle.Fill;
			Controls.Add(host);
		}

		#endregion

		#region Example

		public NWidget CreateExampleContent()
		{
			// Create an array of images to use for the headers of the menu items
			NImage[] BorderSideImages = new NImage[] {
				Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAAGklEQVR4AWOgEviPE0IAgoHJHngFI8UXhAEAEaBEvFnR11sAAAAASUVORK5CYII=")),
				Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAHklEQVR4AWMYPKChoeE/qTT1XUCs+DB0wWgsjMYCACvQUmBkDQR6AAAAAElFTkSuQmCC")),
				Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAANklEQVR4AWMYVOA/qRjTABIA0QYkFDRgFR+2LkDYiKAzClDpBCBN3zDIKBjoWEigpwvIwJQDAP0cRBCXZ9fgAAAAAElFTkSuQmCC")),
				Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAAJ0lEQVR4AWOgDmj4j8AM/1H5mOA/DhMwFdDHBIQgDjg0fEE4LggDAL3eNtRsF20aAAAAAElFTkSuQmCC")),
				Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAAG0lEQVR4AWOgEviPExIJGv7jYNPVBBx45PgCAM7vM9qeQMz0AAAAAElFTkSuQmCC")),
				Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAJElEQVR4AWMYPCAho+A/qTT1XUCs+HB2ARn0aCxQG/wnA1MOAIkvRorIww9hAAAAAElFTkSuQmCC")),
				Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAAH0lEQVR4AWOgEvjPwNCAFSMU4AcIBci6qGzCqC8IAQACPDPa6lsJaAAAAABJRU5ErkJggg==")),
				Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAAH0lEQVR4AWOgDmj4jx0zADEeAFcAVY3BppMJo76AAQDGvTPaiSVsfgAAAABJRU5ErkJggg==")),
				Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAAH0lEQVR4AWOgDmj4jwuTYgImm74mMPzHAYeKLyiPCwDkdTPazw2UjwAAAABJRU5ErkJggg==")),
				Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAAIElEQVR4AWOgDmj4j8AM/1H5mOA/DhMwFdDUhFFfYAIA5HUz2mFFhFcAAAAASUVORK5CYII="))
			};

			// Create a menu split button
			m_MenuSplitButton = new NMenuSplitButton();
			m_MenuSplitButton.HorizontalPlacement = ENHorizontalPlacement.Left;
			m_MenuSplitButton.VerticalPlacement = ENVerticalPlacement.Top;

			// Fill the menu split button drop down menu from an enum and with
			// the images created above for headers
			m_MenuSplitButton.Items.FillFromEnum(BorderSideImages);

			// Subscribe to the SelectedIndexChanged and the Click events
			m_MenuSplitButton.SelectedIndexChanged += OnMenuSplitButtonSelectedIndexChanged;
			m_MenuSplitButton.Click += OnMenuSplitButtonClick;
			return m_MenuSplitButton;
		}
		public NWidget CreateExampleControls()
		{
			NList editors = NDesigner.GetDesigner(m_MenuSplitButton).CreateMemberEditors(
				m_MenuSplitButton,
				NMenuSplitButton.EnabledProperty,
				NMenuSplitButton.HorizontalPlacementProperty,
				NMenuSplitButton.VerticalPlacementProperty,
				NMenuSplitButton.DropDownButtonPositionProperty,
				NMenuSplitButton.SelectedIndexProperty);

			NStackPanel stack = new NStackPanel();
			stack.FillMode = ENStackFillMode.Last;
			stack.FitMode = ENStackFitMode.Last;

			for (int i = 0; i < editors.Count; i++)
			{
				stack.Add(editors[i]);
			}

			m_EventsLog = new NExampleEventsLog();
			stack.Add(m_EventsLog);

			return new NUniSizeBoxGroup(stack);
		}
		public string GetExampleDescription()
		{
			return @"

This example demonstrates how to create and use menu split buttons. Split buttons are drop down edits, whose item slot is filled with an action button, which generates a Click event on behalf of the split button. The menu split button's drop down content is a menu, which allows the user to quickly select an option. This option is then assigned to the action button of the split button and can be activated by clicking the action button.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Split Buttons", "https://www.nevron.com/docs/openvision/ui-split-buttons.html"), ("Drop Down Edits Overview", "https://www.nevron.com/docs/openvision/ui-drop-down-edits-overview.html"), }; } #endregion #region Implementation #endregion #region Event Handlers private void OnMenuSplitButtonSelectedIndexChanged(NValueChangeEventArgs arg) { // Get the selected index int selectedIndex = (int)arg.NewValue; if (selectedIndex == -1) { m_EventsLog.LogEvent("No item selected"); return; } // Obtain and show the selected enum value NMenuSplitButton splitButton = (NMenuSplitButton)arg.CurrentTargetNode; ENTableBorders selectedSide = (ENTableBorders)splitButton.SelectedValue; m_EventsLog.LogEvent("Selected Index: " + selectedIndex.ToString() + " (" + selectedSide.ToString() + ")"); } private void OnMenuSplitButtonClick(NEventArgs arg) { // Get the selected index NMenuSplitButton splitButton = (NMenuSplitButton)arg.CurrentTargetNode; int selectedIndex = splitButton.SelectedIndex; if (selectedIndex == -1) { m_EventsLog.LogEvent("No item selected"); return; } // Obtain and show the selected enum value ENTableBorders selectedSide = (ENTableBorders)splitButton.SelectedValue; m_EventsLog.LogEvent("Action button clicked, index: " + selectedIndex.ToString() + " (" + selectedSide.ToString() + ")"); } #endregion #region Fields private NExampleEventsLog m_EventsLog; private NMenuSplitButton m_MenuSplitButton; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Menu Split Button Example for WPF Solution

VB.NET Menu Split Button Example Code for Nevron UserInterface for WPF
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Editors
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
Imports Nevron.Nov.Presentation
Imports Nevron.Nov.Text
Imports Nevron.Nov.UI
Imports Nevron.Nov.Windows.Wpf

Class MainWindow

#Region "Constructors"

	Public Sub New()
		' This call is required by the designer.
		InitializeComponent()

		' Add any initialization after the InitializeComponent() call.

		' Set form title
		Title = "NOV WPF - NMenuSplitButtonExample"

		' Create the NOV example and its controls
		Dim exampleContent As NWidget = CreateExampleContent()
		Dim exampleControls As NWidget = CreateExampleControls()
		If Not exampleControls Is Nothing Then
			exampleControls.PreferredWidth = 300
		End If

		' Place the example and its controls in a pair box
		Dim pairBox As NPairBox = New NPairBox(exampleContent, exampleControls)
		pairBox.FillMode = ENStackFillMode.First
		pairBox.FitMode = ENStackFitMode.First
		pairBox.Margins = New NMargins(NDesign.HorizontalSpacing, NDesign.VerticalSpacing)

		' Host the example in the form
		Dim host As NNovWidgetHost(Of NWidget) = New NNovWidgetHost(Of NWidget)(pairBox)
		Content = host
	End Sub


#End Region

#Region "Example"

        Public Function CreateExampleContent() As NWidget
            ' Create an array of images to use for the headers of the menu items
            Dim BorderSideImages = New NImage() {NResources.Image_TableBorders_AllBorders_png, Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAHklEQVR4AWMYPKChoeE/qTT1XUCs+DB0wWgsjMYCACvQUmBkDQR6AAAAAElFTkSuQmCC")), Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAANklEQVR4AWMYVOA/qRjTABIA0QYkFDRgFR+2LkDYiKAzClDpBCBN3zDIKBjoWEigpwvIwJQDAP0cRBCXZ9fgAAAAAElFTkSuQmCC")), Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAAJ0lEQVR4AWOgDmj4j8AM/1H5mOA/DhMwFdDHBIQgDjg0fEE4LggDAL3eNtRsF20aAAAAAElFTkSuQmCC")), Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAAG0lEQVR4AWOgEviPExIJGv7jYNPVBBx45PgCAM7vM9qeQMz0AAAAAElFTkSuQmCC")), Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAJElEQVR4AWMYPCAho+A/qTT1XUCs+HB2ARn0aCxQG/wnA1MOAIkvRorIww9hAAAAAElFTkSuQmCC")), Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAAH0lEQVR4AWOgEvjPwNCAFSMU4AcIBci6qGzCqC8IAQACPDPa6lsJaAAAAABJRU5ErkJggg==")), Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAAH0lEQVR4AWOgDmj4jx0zADEeAFcAVY3BppMJo76AAQDGvTPaiSVsfgAAAABJRU5ErkJggg==")), Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAAH0lEQVR4AWOgDmj4jwuTYgImm74mMPzHAYeKLyiPCwDkdTPazw2UjwAAAABJRU5ErkJggg==")), Nevron.Nov.Graphics.NImage.FromBytes(Nevron.Nov.NConvert.FromBase64String("iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAQAAAC1+jfqAAAAIElEQVR4AWOgDmj4j8AM/1H5mOA/DhMwFdDUhFFfYAIA5HUz2mFFhFcAAAAASUVORK5CYII="))}

            ' Create a menu split button
            m_MenuSplitButton = New NMenuSplitButton()
            m_MenuSplitButton.HorizontalPlacement = ENHorizontalPlacement.Left
            m_MenuSplitButton.VerticalPlacement = ENVerticalPlacement.Top

            ' Fill the menu split button drop down menu from an enum and with
            ' the images created above for headers
            m_MenuSplitButton.Items.FillFromEnum(Of ENTableBorders, NImage)(BorderSideImages)

            ' Subscribe to the SelectedIndexChanged and the Click events
            Me.m_MenuSplitButton.SelectedIndexChanged += AddressOf OnMenuSplitButtonSelectedIndexChanged
            Me.m_MenuSplitButton.Click += AddressOf OnMenuSplitButtonClick
            Return m_MenuSplitButton
        End Function
        Public Function CreateExampleControls() As NWidget
            Dim editors = NDesigner.GetDesigner(m_MenuSplitButton).CreateMemberEditors(m_MenuSplitButton, NInputElement.EnabledProperty, NWidget.HorizontalPlacementProperty, NWidget.VerticalPlacementProperty, NDropDownEdit.DropDownButtonPositionProperty, NMenuSplitButton.SelectedIndexProperty)

            Dim stack As NStackPanel = New NStackPanel()
            stack.FillMode = ENStackFillMode.Last
            stack.FitMode = ENStackFitMode.Last

            For i = 0 To editors.Count - 1
                stack.Add(editors(i))
            Next

            m_EventsLog = New NExampleEventsLog()
            stack.Add(m_EventsLog)

            Return New NUniSizeBoxGroup(stack)
        End Function
        Public Function GetExampleDescription() As String
            Return "

This example demonstrates how to create and use menu split buttons. Split buttons are drop down edits, whose item slot is filled with an action button, which generates a Click event on behalf of the split button. The menu split button's drop down content is a menu, which allows the user to quickly select an option. This option is then assigned to the action button of the split button and can be activated by clicking the action button.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Split Buttons", "https://www.nevron.com/docs/openvision/ui-split-buttons.html"), ("Drop Down Edits Overview", "https://www.nevron.com/docs/openvision/ui-drop-down-edits-overview.html")} End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" Private Sub OnMenuSplitButtonSelectedIndexChanged(arg As NValueChangeEventArgs) ' Get the selected index Dim selectedIndex As Integer = arg.NewValue If selectedIndex = -1 Then m_EventsLog.LogEvent("No item selected") Return End If ' Obtain and show the selected enum value Dim splitButton = CType(arg.CurrentTargetNode, NMenuSplitButton) Dim selectedSide As ENTableBorders = splitButton.SelectedValue m_EventsLog.LogEvent("Selected Index: " & selectedIndex.ToString() & " (" & selectedSide.ToString() & ")") End Sub Private Sub OnMenuSplitButtonClick(arg As NEventArgs) ' Get the selected index Dim splitButton = CType(arg.CurrentTargetNode, NMenuSplitButton) Dim selectedIndex = splitButton.SelectedIndex If selectedIndex = -1 Then m_EventsLog.LogEvent("No item selected") Return End If ' Obtain and show the selected enum value Dim selectedSide As ENTableBorders = splitButton.SelectedValue m_EventsLog.LogEvent("Action button clicked, index: " & selectedIndex.ToString() & " (" & selectedSide.ToString() & ")") End Sub #End Region #Region "Fields" Private m_EventsLog As NExampleEventsLog Private m_MenuSplitButton As NMenuSplitButton #End Region #Region "Static Methods" #End Region #Region "Constants" #End Region #Region "Nested Types" #End Region End Class

Download a fully functional VB.NET (.vb) Menu Split Button Example for WPF Solution

Related Documentation Links