Mixed Content 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.

Mixed Content Example for Blazor Description

This example demonstrates how to create a list box and add items with various content to it - text only items, items with image and text, checkable items and so on. Using the controls to the right you can modify the appearance and the behavior of the list box.


List Box Mixed Content Example

C# Mixed Content 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;
using System.Windows.Forms;

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

		public Form1()
		{
			InitializeComponent();

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

			// 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 a list box
			m_ListBox = new NListBox();
			m_ListBox.HorizontalPlacement = ENHorizontalPlacement.Left;
			m_ListBox.PreferredSize = new NSize(200, 400);

			// Fill the image Box
			FillWithImageCheckBoxAndTitle();

			// Hook to list box selection events
			m_ListBox.Selection.Selected += OnListBoxItemSelected;
			m_ListBox.Selection.Deselected += OnListBoxItemDeselected;

			return m_ListBox;
		}
		public NWidget CreateExampleControls()
		{
			NStackPanel stack = new NStackPanel();
			stack.FillMode = ENStackFillMode.Last;
			stack.FitMode = ENStackFitMode.Last;

			// Create the content type group box
			NEditor contentTypePropertyEditor = NDesigner.GetDesigner(this).CreateMemberEditor(this, ContentTypeProperty);
			stack.Add(contentTypePropertyEditor);

			// Create the properties group box
			NStackPanel propertiesStack = new NStackPanel();
			NList editors = NDesigner.GetDesigner(m_ListBox).CreateMemberEditors(m_ListBox,
				NWidget.EnabledProperty,
				NWidget.HorizontalPlacementProperty,
				NWidget.VerticalPlacementProperty,
				NScrollContentBase.HScrollModeProperty,
				NScrollContentBase.VScrollModeProperty,
				NScrollContentBase.NoScrollHAlignProperty,
				NScrollContentBase.NoScrollVAlignProperty,
				NListBox.IntegralVScrollProperty
			);

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

			NGroupBox propertiesGroupBox = new NGroupBox("Properties", new NUniSizeBoxGroup(propertiesStack));
			stack.Add(propertiesGroupBox);

			// Create the events log
			m_EventsLog = new NExampleEventsLog();
			stack.Add(m_EventsLog);

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

This example demonstrates how to create a list box and add items with various content to it - text only items, items with image and text, checkable items and so on. Using the controls to the right you can modify the appearance and the behavior of the list box.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("List Box", "https://www.nevron.com/docs/openvision/ui-list-box.html"), ("Widget Elements", "https://www.nevron.com/docs/openvision/ui-widget-elements.html"), ("Containers Overview", "https://www.nevron.com/docs/openvision/ui-containers-overview.html"), ("Label", "https://www.nevron.com/docs/openvision/ui-label.html"), }; } #endregion #region Implementation private NListBoxItem CreateListBoxItem(int index, bool hasCheckBox, bool hasImage) { string text = "Item " + index.ToString(); if (hasCheckBox == false && hasImage == false) return new NListBoxItem(text); NStackPanel stack = new NStackPanel(); stack.Direction = ENHVDirection.LeftToRight; stack.HorizontalSpacing = 3; if (hasCheckBox) { NCheckBox checkBox = new NCheckBox(); checkBox.VerticalPlacement = ENVerticalPlacement.Center; stack.Add(checkBox); } if (hasImage) { stack.Add(CreateImageBox(index)); } NLabel label = new NLabel(text); label.VerticalPlacement = ENVerticalPlacement.Center; stack.Add(label); return new NListBoxItem(stack); } private void FillWithImageCheckBoxAndTitle() { m_ListBox.Items.Clear(); for (int i = 0; i < 100; i++) { int index = (i % 32) / 8; bool checkBox = index == 1 || index == 3; bool image = index == 2 || index == 3; m_ListBox.Items.Add(CreateListBoxItem(i, checkBox, image)); } } private NListBoxItem CreateDetailedListBoxItem(int index) { NDockPanel dock = new NDockPanel(); dock.HorizontalSpacing = 3; dock.Padding = new NMargins(0, 2, 0, 2); dock.Add(CreateImageBox(index)); // Add the title NLabel titleLabel = new NLabel("Item " + index.ToString()); titleLabel.Font = new NFont(NFontDescriptor.DefaultSansFamilyName, 10, ENFontStyle.Bold); NDockLayout.SetDockArea(titleLabel, ENDockArea.Top); dock.AddChild(titleLabel); // Add the description NLabel descriptionLabel = new NLabel("This is item " + index.ToString() + "'s description."); NDockLayout.SetDockArea(descriptionLabel, ENDockArea.Center); dock.AddChild(descriptionLabel); return new NListBoxItem(dock); } private void FillWithImageTitleAndDetails() { m_ListBox.Items.Clear(); for (int i = 0; i < 100; i++) { m_ListBox.Items.Add(CreateDetailedListBoxItem(i)); } } /// /// /// /// /// private static NImageBox CreateImageBox(int index) { string[] imageNames = new string[] { "Calendar", "Contacts", "Folders", "Journal", "Mail", "Notes", "Shortcuts", "Tasks" }; NEmbeddedResource[] imageResources = new NEmbeddedResource[] { Nevron.Nov.Examples.NResources.RIMG__16x16_Calendar_png, Nevron.Nov.Examples.NResources.RIMG__16x16_Contacts_png, Nevron.Nov.Examples.NResources.RIMG__16x16_Folders_png, Nevron.Nov.Examples.NResources.RIMG__16x16_Journal_png, Nevron.Nov.Examples.NResources.RIMG__16x16_Mail_png, Nevron.Nov.Examples.NResources.RIMG__16x16_Notes_png, Nevron.Nov.Examples.NResources.RIMG__16x16_Shortcuts_png, Nevron.Nov.Examples.NResources.RIMG__16x16_Tasks_png }; // Add the image int imageIndex = index % imageNames.Length; string imageName = imageNames[imageIndex]; NImage icon = new NImage(new NEmbeddedResourceRef(imageResources[imageIndex])); NImageBox imageBox = new NImageBox(icon); imageBox.HorizontalPlacement = ENHorizontalPlacement.Center; imageBox.VerticalPlacement = ENVerticalPlacement.Center; NDockLayout.SetDockArea(imageBox, ENDockArea.Left); return imageBox; } #endregion #region Event Handlers private void OnListBoxItemSelected(NItemEventArgs args) { NListBoxItem item = args.Item; int index = item.GetAggregationInfo().Index; m_EventsLog.LogEvent("Selected Item: " + index.ToString()); } private void OnListBoxItemDeselected(NItemEventArgs args) { NListBoxItem item = args.Item; int index = item.GetAggregationInfo().Index; m_EventsLog.LogEvent("Deselected Item: " + index.ToString()); } /// /// Called when the ContentType property has changed. /// /// private void OnContentTypeChanged(NValueChangeData data) { switch ((ENListBoxContentType)data.NewValue) { case ENListBoxContentType.ImageCheckBoxAndTitle: FillWithImageCheckBoxAndTitle(); break; case ENListBoxContentType.ImageTitleAndDetails: FillWithImageTitleAndDetails(); break; default: throw new Exception("New ENListBoxContentType?"); } } #endregion #region Fields private NListBox m_ListBox; private NExampleEventsLog m_EventsLog; #endregion #region Static Methods #endregion #region Constants private const ENListBoxContentType defaultContentType = ENListBoxContentType.ImageCheckBoxAndTitle; #endregion #region Nested Types public enum ENListBoxContentType { ImageCheckBoxAndTitle, ImageTitleAndDetails } /// /// Designer for NListBoxMixedContent. /// public class NListBoxMixedContentDesigner : NDesigner { /// /// Default constructor. /// public NListBoxMixedContentDesigner() { SetMemberEditorFactory(ContentTypeProperty, NEnumPropertyEditor.VerticalRadioGroupFactory); } } #endregion } }

Download a fully functional C# (.cs) Mixed Content Example for Blazor Solution