Resize Mode Example for WPF

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

Resize Mode Example for WPF Description

Demonstrates the table resize modes. Table support three resize modes:
AutoSize - The table desired size determines the size of the table containing shape
AutoHeight - The table containing shape defines the table witdth, while the table contents defines the table containing shape height
Stretch - The table is stretched to fit the bounds specified by its containing shape. If the table cannot fit it will resize the table containing shape automatically.


Table Resize Mode Example

C# Resize Mode Example Code for Nevron Diagram for WPF
Language: C#

using Nevron.Nov;
using Nevron.Nov.Diagram;
using Nevron.Nov.Dom;
using Nevron.Nov.Graphics;
using Nevron.Nov.Layout;
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 - NTableResizeModeExample";

			// 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 simple drawing
			NDrawingViewWithRibbon drawingViewWithRibbon = new NDrawingViewWithRibbon();
			m_DrawingView = drawingViewWithRibbon.View;

			m_DrawingView.Document.HistoryService.Pause();
			try
			{
				InitDiagram(m_DrawingView.Document);
			}
			finally
			{
				m_DrawingView.Document.HistoryService.Resume();
			}

			return drawingViewWithRibbon;
		}
		public NWidget CreateExampleControls()
		{
			return null;
		}
		public string GetExampleDescription()
        {
            return @"

Demonstrates the table resize modes. Table support three resize modes:
AutoSize - The table desired size determines the size of the table containing shape
AutoHeight - The table containing shape defines the table witdth, while the table contents defines the table containing shape height
Stretch - The table is stretched to fit the bounds specified by its containing shape. If the table cannot fit it will resize the table containing shape automatically.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Shapes", "https://www.nevron.com/docs/openvision/diagram-shapes.html"), ("Rich Text Tables", "https://www.nevron.com/docs/openvision/rich-text-tables.html"), }; } private void InitDiagram(NDrawingDocument drawingDocument) { NDrawing drawing = drawingDocument.Content; NPage activePage = drawing.ActivePage; // hide the grid drawing.ScreenVisibility.ShowGrid = false; string[] tableDescription = new string[] { "Table in Auto Size Mode", "Table in Auto Height Mode", "Table in Fit To Shape Mode" }; ENTableBlockResizeMode[] tableBlockResizeMode = new ENTableBlockResizeMode[] { ENTableBlockResizeMode.AutoSize, ENTableBlockResizeMode.AutoHeight, ENTableBlockResizeMode.FitToShape }; double y = 100; for (int i = 0; i < 3; i++) { NShape shape = new NShape(); shape.SetBounds(new NRectangle(100, y, 300, 300)); y += 200; // create table NTableBlock tableBlock = CreateTableBlock(tableDescription[i]); tableBlock.Content.AllowSpacingBetweenCells = false; tableBlock.ResizeMode = tableBlockResizeMode[i]; shape.TextBlock = tableBlock; activePage.Items.AddChild(shape); } } private NTableBlock CreateTableBlock(string description) { NTableBlock tableBlock = new NTableBlock(4, 3, NBorder.CreateFilledBorder(NColor.Black), new NMargins(1)); NTableBlockContent tableBlockContent = tableBlock.Content; NTableCell tableCell = tableBlock.Content.Rows[0].Cells[0]; tableCell.ColSpan = int.MaxValue; tableCell.Blocks.Clear(); NParagraph par = new NParagraph(description); par.FontStyleBold = true; tableCell.Blocks.Add(par); for (int rowIndex = 1; rowIndex < tableBlockContent.Rows.Count; rowIndex++) { NTableRow row = tableBlockContent.Rows[rowIndex]; for (int colIndex = 0; colIndex < tableBlockContent.Columns.Count; colIndex++) { NTableCell cell = row.Cells[colIndex]; cell.Blocks.Clear(); cell.Blocks.Add(new NParagraph("This is a table cell [" + rowIndex.ToString() + ", " + colIndex.ToString() + "]")); } } NTableCellIterator iter = new NTableCellIterator(tableBlockContent); while (iter.MoveNext()) { iter.Current.VerticalAlignment = ENVAlign.Center; iter.Current.HorizontalAlignment = ENAlign.Center; } // make sure all columns are percentage based double percent = 100 / tableBlockContent.Columns.Count; for (int i = 0; i < tableBlockContent.Columns.Count; i++) { tableBlockContent.Columns[i].PreferredWidth = new Nevron.Nov.NMultiLength(Nevron.Nov.ENMultiLengthUnit.Percentage, percent); } return tableBlock; } #endregion #region Implementation /// /// Adds rich formatted text to the specified text block content /// /// private void AddFormattedTextToContent(NTextBlockContent content) { content.Blocks.Add(GetTitleParagraph("Bullet lists allow you to apply automatic numbering on paragraphs or groups of blocks.", 1)); // setting bullet list template type { content.Blocks.Add(GetTitleParagraph("Following are bullet lists with different formatting", 2)); ENBulletListTemplateType[] values = NEnum.GetValues(); string[] names = NEnum.GetNames(); string itemText = "Bullet List Item"; for (int i = 0; i < values.Length - 1; i++) { NGroupBlock group = new NGroupBlock(); content.Blocks.Add(group); group.MarginTop = 10; group.MarginBottom = 10; NBulletList bulletList = new NBulletList(values[i]); content.BulletLists.Add(bulletList); for (int j = 0; j < 3; j++) { NParagraph paragraph = new NParagraph(itemText + j.ToString()); NBulletInline bullet = new NBulletInline(); bullet.List = bulletList; paragraph.Bullet = bullet; group.Blocks.Add(paragraph); } } } // nested bullet lists { content.Blocks.Add(GetTitleParagraph("Following is an example of bullets with different bullet level", 2)); NBulletList bulletList = new NBulletList(ENBulletListTemplateType.Decimal); content.BulletLists.Add(bulletList); NGroupBlock group = new NGroupBlock(); content.Blocks.Add(group); for (int i = 0; i < 3; i++) { NParagraph par = new NParagraph("Bullet List Item" + i.ToString(), bulletList, 0); group.Blocks.Add(par); for (int j = 0; j < 2; j++) { NParagraph nestedPar = new NParagraph("Nested Bullet List Item" + i.ToString(), bulletList, 1); nestedPar.MarginLeft = 10; group.Blocks.Add(nestedPar); } } } } /// /// /// /// /// /// internal static NParagraph GetTitleParagraphNoBorder(string text, int level) { double fontSize = 10; ENFontStyle fontStyle = ENFontStyle.Regular; switch (level) { case 1: fontSize = 16; fontStyle = ENFontStyle.Bold; break; case 2: fontSize = 10; fontStyle = ENFontStyle.Bold; break; } NParagraph paragraph = new NParagraph(); paragraph.HorizontalAlignment = ENAlign.Left; paragraph.FontSize = fontSize; paragraph.FontStyle = fontStyle; NTextInline textInline = new NTextInline(text); textInline.FontStyle = fontStyle; textInline.FontSize = fontSize; paragraph.Inlines.Add(textInline); return paragraph; } /// /// Gets a paragraph with title formatting /// /// /// internal static NParagraph GetTitleParagraph(string text, int level) { NColor color = NColor.Black; NParagraph paragraph = GetTitleParagraphNoBorder(text, level); paragraph.HorizontalAlignment = ENAlign.Left; paragraph.Border = CreateLeftTagBorder(color); paragraph.BorderThickness = new NMargins(5.0, 0.0, 0.0, 0.0); return paragraph; } /// /// Creates a left tag border with the specified border /// /// /// private static NBorder CreateLeftTagBorder(NColor color) { NBorder border = new NBorder(); border.LeftSide = new NBorderSide(); border.LeftSide.Fill = new NColorFill(color); return border; } #endregion #region Event Handlers #endregion #region Fields private NDrawingView m_DrawingView; #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Resize Mode Example for WPF Solution

VB.NET Resize Mode Example Code for Nevron Diagram for WPF
Language: VB.NET

Imports Nevron.Nov
Imports Nevron.Nov.Diagram
Imports Nevron.Nov.Dom
Imports Nevron.Nov.Graphics
Imports Nevron.Nov.Layout
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 - NTableResizeModeExample"

		' 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 a simple drawing
            Dim drawingViewWithRibbon As NDrawingViewWithRibbon = New NDrawingViewWithRibbon()
            m_DrawingView = drawingViewWithRibbon.View

            m_DrawingView.Document.HistoryService.Pause()
            Try
                InitDiagram(m_DrawingView.Document)
            Finally
                m_DrawingView.Document.HistoryService.Resume()
            End Try

            Return drawingViewWithRibbon
        End Function
        Public Function CreateExampleControls() As NWidget
            Return Nothing
        End Function
        Public Function GetExampleDescription() As String
            Return "

Demonstrates the table resize modes. Table support three resize modes:
AutoSize - The table desired size determines the size of the table containing shape
AutoHeight - The table containing shape defines the table witdth, while the table contents defines the table containing shape height
Stretch - The table is stretched to fit the bounds specified by its containing shape. If the table cannot fit it will resize the table containing shape automatically.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Shapes", "https://www.nevron.com/docs/openvision/diagram-shapes.html"), ("Rich Text Tables", "https://www.nevron.com/docs/openvision/rich-text-tables.html")} End Function Private Sub InitDiagram(drawingDocument As NDrawingDocument) Dim drawing = drawingDocument.Content Dim activePage = drawing.ActivePage ' hide the grid drawing.ScreenVisibility.ShowGrid = False Dim tableDescription = New String() {"Table in Auto Size Mode", "Table in Auto Height Mode", "Table in Fit To Shape Mode"} Dim tableBlockResizeMode = New ENTableBlockResizeMode() {ENTableBlockResizeMode.AutoSize, ENTableBlockResizeMode.AutoHeight, ENTableBlockResizeMode.FitToShape} Dim y As Double = 100 For i = 0 To 2 Dim shape As NShape = New NShape() shape.SetBounds(New NRectangle(100, y, 300, 300)) y += 200 ' create table Dim tableBlock = CreateTableBlock(tableDescription(i)) tableBlock.Content.AllowSpacingBetweenCells = False tableBlock.ResizeMode = tableBlockResizeMode(i) shape.TextBlock = tableBlock activePage.Items.AddChild(shape) Next End Sub Private Function CreateTableBlock(description As String) As NTableBlock Dim tableBlock As NTableBlock = New NTableBlock(4, 3, NBorder.CreateFilledBorder(NColor.Black), New NMargins(1)) Dim tableBlockContent = tableBlock.Content Dim tableCell = tableBlock.Content.Rows(0).Cells(0) tableCell.ColSpan = Integer.MaxValue tableCell.Blocks.Clear() Dim par As NParagraph = New NParagraph(description) par.FontStyleBold = True tableCell.Blocks.Add(par) For rowIndex = 1 To tableBlockContent.Rows.Count - 1 Dim row = tableBlockContent.Rows(rowIndex) For colIndex = 0 To tableBlockContent.Columns.Count - 1 Dim cell = row.Cells(colIndex) cell.Blocks.Clear() cell.Blocks.Add(New NParagraph("This is a table cell [" & rowIndex.ToString() & ", " & colIndex.ToString() & "]")) Next Next Dim iter As NTableCellIterator = New NTableCellIterator(tableBlockContent) While iter.MoveNext() iter.Current.VerticalAlignment = ENVAlign.Center iter.Current.HorizontalAlignment = ENAlign.Center End While ' make sure all columns are percentage based Dim percent = 100 / tableBlockContent.Columns.Count For i = 0 To tableBlockContent.Columns.Count - 1 tableBlockContent.Columns(i).PreferredWidth = New NMultiLength(ENMultiLengthUnit.Percentage, percent) Next Return tableBlock End Function #End Region #Region "Implementation" #End Region #Region "Event Handlers" #End Region #Region "Fields" Private m_DrawingView As NDrawingView #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) Resize Mode Example for WPF Solution

Related Documentation Links