Resize in Groups 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 in Groups Example for WPF Description

Demonstrates how 2D and 1D shapes can be resized when they are placed in groups.

When a 2D shape whose ResizeInGroup property is set to ScaleAndReposition is resized inside a group, NOV Diagram will express the shape size as a fraction of the group Width and Height, and bind the shape pin point to a relative position inside group coordinate system. When the group is resized, the 2D shape will scale and reposition with the group.

When a 2D shape whose ResizeInGroup property is set to RepositionOnly is resized inside a group, NOV Diagram will set a constant size to the shape and bind the shape pin point to a relative position inside group coordinate system. When the group is resized, the 2D shape will only reposition itself.

When you move the Begin or End points of a 1D shape inside a group, NOV Diagram will bind the respective end-point to a relative position inside group coordinate system. When the group is resized, the 1D shape will get stretched.


Resize in Groups Example

C# Resize in Groups Example Code for Nevron Diagram for WPF
Language: C#

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

			// 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 how 2D and 1D shapes can be resized when they are placed in groups.

When a 2D shape whose ResizeInGroup property is set to ScaleAndReposition is resized inside a group, NOV Diagram will express the shape size as a fraction of the group Width and Height, and bind the shape pin point to a relative position inside group coordinate system. When the group is resized, the 2D shape will scale and reposition with the group.

When a 2D shape whose ResizeInGroup property is set to RepositionOnly is resized inside a group, NOV Diagram will set a constant size to the shape and bind the shape pin point to a relative position inside group coordinate system. When the group is resized, the 2D shape will only reposition itself.

When you move the Begin or End points of a 1D shape inside a group, NOV Diagram will bind the respective end-point to a relative position inside group coordinate system. When the group is resized, the 1D shape will get stretched.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Groups", "https://www.nevron.com/docs/openvision/diagram-groups.html"), ("Shapes", "https://www.nevron.com/docs/openvision/diagram-shapes.html"), }; } private void InitDiagram(NDrawingDocument drawingDocument) { // create the group NGroup group = new NGroup(); // make some background for the group NDrawRectangle drawRect = new NDrawRectangle(0, 0, 1, 1); drawRect.Relative = true; group.Geometry.Add(drawRect); group.Geometry.Fill = new NColorFill(NColor.LightCoral); group.SetBounds(new NRectangle(50, 50, 230, 330)); NBasicShapeFactory basicShapes = new NBasicShapeFactory(); NConnectorShapeFactory connectorShapes = new NConnectorShapeFactory(); // create a rectangle that is scaled and repositioned NShape rect1 = basicShapes.CreateShape(ENBasicShape.Rectangle); rect1.Text = "Scale and Reposition"; group.Shapes.Add(rect1); rect1.ResizeInGroup = ENResizeInGroup.ScaleAndReposition; rect1.SetBounds(new NRectangle(10, 10, 100, 100)); // create a rectangle that is only repositioned NShape rect2 = basicShapes.CreateShape(ENBasicShape.Rectangle); rect2.Text = "Reposition Only"; group.Shapes.Add(rect2); rect2.ResizeInGroup = ENResizeInGroup.RepositionOnly; rect2.SetBounds(new NRectangle(120, 120, 100, 100)); // create a 1D shape NShape arrow = connectorShapes.CreateShape(ENConnectorShape.Single45DegreesArrow); arrow.Text = "1D Shape"; group.Shapes.Add(arrow); arrow.SetBeginPoint(new NPoint(10, 250)); arrow.SetEndPoint(new NPoint(220, 290)); // add the group drawingDocument.Content.ActivePage.Items.Add(group); } #endregion #region Implementation #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 in Groups Example for WPF Solution

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

Imports Nevron.Nov
Imports Nevron.Nov.Diagram
Imports Nevron.Nov.Diagram.Shapes
Imports Nevron.Nov.Dom
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 - NResizeInGroupsExample"

		' 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 how 2D and 1D shapes can be resized when they are placed in groups.

When a 2D shape whose ResizeInGroup property is set to ScaleAndReposition is resized inside a group, NOV Diagram will express the shape size as a fraction of the group Width and Height, and bind the shape pin point to a relative position inside group coordinate system. When the group is resized, the 2D shape will scale and reposition with the group.

When a 2D shape whose ResizeInGroup property is set to RepositionOnly is resized inside a group, NOV Diagram will set a constant size to the shape and bind the shape pin point to a relative position inside group coordinate system. When the group is resized, the 2D shape will only reposition itself.

When you move the Begin or End points of a 1D shape inside a group, NOV Diagram will bind the respective end-point to a relative position inside group coordinate system. When the group is resized, the 1D shape will get stretched.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Groups", "https://www.nevron.com/docs/openvision/diagram-groups.html"), ("Shapes", "https://www.nevron.com/docs/openvision/diagram-shapes.html")} End Function Private Sub InitDiagram(drawingDocument As NDrawingDocument) ' create the group Dim group As NGroup = New NGroup() ' make some background for the group Dim drawRect As NDrawRectangle = New NDrawRectangle(0, 0, 1, 1) drawRect.Relative = True group.Geometry.Add(drawRect) group.Geometry.Fill = New NColorFill(NColor.LightCoral) group.SetBounds(New NRectangle(50, 50, 230, 330)) Dim basicShapes As NBasicShapeFactory = New NBasicShapeFactory() Dim connectorShapes As NConnectorShapeFactory = New NConnectorShapeFactory() ' create a rectangle that is scaled and repositioned Dim rect1 = basicShapes.CreateShape(ENBasicShape.Rectangle) rect1.Text = "Scale and Reposition" group.Shapes.Add(rect1) rect1.ResizeInGroup = ENResizeInGroup.ScaleAndReposition rect1.SetBounds(New NRectangle(10, 10, 100, 100)) ' create a rectangle that is only repositioned Dim rect2 = basicShapes.CreateShape(ENBasicShape.Rectangle) rect2.Text = "Reposition Only" group.Shapes.Add(rect2) rect2.ResizeInGroup = ENResizeInGroup.RepositionOnly rect2.SetBounds(New NRectangle(120, 120, 100, 100)) ' create a 1D shape Dim arrow = connectorShapes.CreateShape(ENConnectorShape.Single45DegreesArrow) arrow.Text = "1D Shape" group.Shapes.Add(arrow) arrow.SetBeginPoint(New NPoint(10, 250)) arrow.SetEndPoint(New NPoint(220, 290)) ' add the group drawingDocument.Content.ActivePage.Items.Add(group) End Sub #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 in Groups Example for WPF Solution

Related Documentation Links