Unisize Box Example for Blazor

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

Unisize Box Example for Blazor 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 Blazor
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 Blazor Solution

Related Documentation Links