Unisize Box 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.

Unisize Box Example for WPF Description

This example demonstrates how to create several pair boxes and place them in an alignable element container. Alignable element containers let the user specify how to size the alignable elements in the container.


Uni Size Box Example

C# Unisize Box 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.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 - NUniSizeBoxExample";

			// 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()
		{
			NStackPanel stack = new NStackPanel();
			stack.HorizontalPlacement = ENHorizontalPlacement.Left;
			stack.VerticalPlacement = ENVerticalPlacement.Top;

			m_PairBoxes = new NPairBox[Texts.Length / 2];
			for (int i = 0; i < m_PairBoxes.Length; i++)
			{
				NPairBox pairBox = new NPairBox(new NLabel(Texts[i * 2]), new NLabel(Texts[i * 2 + 1]), true);
				
				pairBox.Box1.SetBorder(1, NColor.Blue);
                pairBox.Box2.SetBorder(1, NColor.Red);

                m_PairBoxes[i] = pairBox;
				stack.Add(pairBox);
			}

			return new NUniSizeBoxGroup(stack);
		}
		public NWidget CreateExampleControls()
		{
			NStackPanel stack = new NStackPanel();
			
			for (int i = 0, count = m_PairBoxes.Length; i < count; i++)
			{
				// Create the pair box property editors
				NPairBox pairBox = m_PairBoxes[i];
				NList editors = NDesigner.GetDesigner(pairBox).CreateMemberEditors(
					pairBox,
					NPairBox.FillModeProperty,
					NPairBox.FitModeProperty);

				NUniSizeBox box1 = (NUniSizeBox)pairBox.Box1;
				editors.Add(NDesigner.GetDesigner(box1).CreateMemberEditor(
					box1,
					NUniSizeBox.UniSizeModeProperty
				));

				NUniSizeBox box2 = (NUniSizeBox)pairBox.Box2;
				editors.Add(NDesigner.GetDesigner(box2).CreateMemberEditor(
					box2,
					NUniSizeBox.UniSizeModeProperty
				));

				// Create the properties stack panel
				NStackPanel propertyStack = new NStackPanel();
				for (int j = 0, editorCount = editors.Count; j < editorCount; j++)
				{
					propertyStack.Add(editors[j]);
				}

                // Add the box 1 preferred height editor
                NEditor editor = NDesigner.GetDesigner(box1.Content).CreateMemberEditor(box1.Content, NWidget.PreferredHeightProperty);
				NLabel label = editor.GetFirstDescendant();
				label.Text = "Box 1 Preferred Height:";
				propertyStack.Add(editor);

				// Add the box 2 preferred height editor
				editor = NDesigner.GetDesigner(box2.Content).CreateMemberEditor(box2.Content, NWidget.PreferredHeightProperty);
				label = editor.GetFirstDescendant();
				label.Text = "Box 2 Preferred Height:";
				propertyStack.Add(editor);

				// Create a group box for the properties
				NGroupBox groupBox = new NGroupBox("Pair Box " + (i + 1).ToString());
				groupBox.Content = propertyStack;
				stack.Add(groupBox);
			}

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

This example demonstrates how to create several pair boxes and place them in an alignable element container. Alignable element containers let the user specify how to size the alignable elements in the container.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Unisize Box", "https://www.nevron.com/docs/openvision/ui-unisize-box.html"), ("Containers Overview", "https://www.nevron.com/docs/openvision/ui-containers-overview.html"), }; } #endregion #region Implementation #endregion #region Event Handlers #endregion #region Fields private NPairBox[] m_PairBoxes; #endregion #region Static Methods #endregion #region Constants private static readonly string[] Texts = new string[] { "This is box 1.1", "I'm box 1.2 and I'm wider", "Box 2.1", "Box 2.2", "I am box 3.1 and I am the widest one", "The last box - 3.2" }; #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Unisize Box Example for WPF Solution

VB.NET Unisize Box 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.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 - NUniSizeBoxExample"

		' 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
            Dim stack As NStackPanel = New NStackPanel()
            stack.HorizontalPlacement = ENHorizontalPlacement.Left
            stack.VerticalPlacement = ENVerticalPlacement.Top

            m_PairBoxes = New NPairBox(Texts.Length / 2 - 1) {}
            For i = 0 To m_PairBoxes.Length - 1
                Dim pairBox As NPairBox = New NPairBox(New NLabel(Texts(i * 2)), New NLabel(Texts(i * 2 + 1)), True)

                pairBox.Box1.SetBorder(1, NColor.Blue)
                pairBox.Box2.SetBorder(1, NColor.Red)

                m_PairBoxes(i) = pairBox
                stack.Add(pairBox)
            Next

            Return New NUniSizeBoxGroup(stack)
        End Function
        Public Function CreateExampleControls() As NWidget
            Dim stack As NStackPanel = New NStackPanel()

            Dim i = 0, count = m_PairBoxes.Length

            While i < count
                ' Create the pair box property editors
                Dim pairBox = m_PairBoxes(i)
                Dim editors = NDesigner.GetDesigner(pairBox).CreateMemberEditors(pairBox, NPairBox.FillModeProperty, NPairBox.FitModeProperty)

                Dim box1 = CType(pairBox.Box1, NUniSizeBox)
                editors.Add(NDesigner.GetDesigner(box1).CreateMemberEditor(box1, NUniSizeBox.UniSizeModeProperty))

                Dim box2 = CType(pairBox.Box2, NUniSizeBox)
                editors.Add(NDesigner.GetDesigner(box2).CreateMemberEditor(box2, NUniSizeBox.UniSizeModeProperty))

                ' Create the properties stack panel
                Dim propertyStack As NStackPanel = New NStackPanel()
                Dim j = 0, editorCount = editors.Count

                While j < editorCount
                    propertyStack.Add(editors(j))
                    j += 1
                End While

                ' Add the box 1 preferred height editor
                Dim editor As NEditor = NDesigner.GetDesigner(box1.Content).CreateMemberEditor(box1.Content, NBoxElement.PreferredHeightProperty)
                Dim label As NLabel = editor.GetFirstDescendant(Of NLabel)()
                label.Text = "Box 1 Preferred Height:"
                propertyStack.Add(editor)

                ' Add the box 2 preferred height editor
                editor = NDesigner.GetDesigner(box2.Content).CreateMemberEditor(box2.Content, NBoxElement.PreferredHeightProperty)
                label = editor.GetFirstDescendant(Of NLabel)()
                label.Text = "Box 2 Preferred Height:"
                propertyStack.Add(editor)

                ' Create a group box for the properties
                Dim groupBox As NGroupBox = New NGroupBox("Pair Box " & (i + 1).ToString())
                groupBox.Content = propertyStack
                stack.Add(groupBox)
                i += 1
            End While

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

This example demonstrates how to create several pair boxes and place them in an alignable element container. Alignable element containers let the user specify how to size the alignable elements in the container.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Unisize Box", "https://www.nevron.com/docs/openvision/ui-unisize-box.html"), ("Containers Overview", "https://www.nevron.com/docs/openvision/ui-containers-overview.html")} End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" #End Region #Region "Fields" Private m_PairBoxes As NPairBox() #End Region #Region "Static Methods" #End Region #Region "Constants" Private Shared ReadOnly Texts As String() = New String() {"This is box 1.1", "I'm box 1.2 and I'm wider", "Box 2.1", "Box 2.2", "I am box 3.1 and I am the widest one", "The last box - 3.2"} #End Region #Region "Nested Types" #End Region End Class

Download a fully functional VB.NET (.vb) Unisize Box Example for WPF Solution

Related Documentation Links