Shape Hyperlinks 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.

Shape Hyperlinks Example for WPF Description

This example demonstrates how to add hyperlinks to shapes. Shape hyperlinks allow you to navigate to an URL, page, shape, bookmark or to open a file. Ctrl + Click on a shape with hyperlink to navigate to the hyperlink target.


Shape Hyperlinks Example

C# Shape Hyperlinks 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;
using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

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

		public Form1()
		{
			InitializeComponent();

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

			// 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()
		{
			NDrawingViewWithRibbon drawingViewWithRibbon = new NDrawingViewWithRibbon();
			NDrawingView drawingView = drawingViewWithRibbon.View;

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

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

This example demonstrates how to add hyperlinks to shapes. Shape hyperlinks allow you to navigate to an URL, page, shape, bookmark or to open a file. Ctrl + Click on a shape with hyperlink to navigate to the hyperlink target.

"; } /// /// Gets the relevant documentation links for the example /// /// public (string Name, string Url)[] GetDocumentationUrls() { return new[] { ("Shape Hyperlink", "https://www.nevron.com/docs/openvision/diagram-shape-hyperlink.html"), ("Shapes", "https://www.nevron.com/docs/openvision/diagram-shapes.html"), }; } private void InitDiagram(NDrawingDocument drawingDocument) { const double TitleWidth = 100; const double TitleFontSize = 16; // Get the drawing and the active (first) page NDrawing drawing = drawingDocument.Content; NPage page1 = drawing.ActivePage; // Create a second page and a bookmark on it NPage page2 = new NPage(); drawing.Pages.Add(page2); NBookmark bookmark = new NBookmark("MyBookmark", 0, 0, 1.5); page2.BookmarkManager.Bookmarks.Add(bookmark); NBasicShapeFactory factory = new NBasicShapeFactory(); factory.DefaultSize = new NSize(160, 100); // Page 1 NShape title1 = new NShape(); title1.Text = "Page 1"; title1.SetBounds((page1.Width - TitleWidth) / 2, 20, TitleWidth, 30); title1.TextBlock.FontSize = TitleFontSize; page1.Items.Add(title1); NShape shape1 = factory.CreateShape(ENBasicShape.Ellipse); shape1.SetPinPoint(100, 200); shape1.Text = "Go to page 2"; shape1.Hyperlink = new NShapeHyperlink(page2); shape1.Ports.RemoveAt(0); shape1.Style = new NShapeStyle(101, 101); page1.Items.Add(shape1); NShape shape2 = factory.CreateShape(ENBasicShape.SixPointStar); shape2.SetPinPoint(350, 200); shape2.Size = new NSize(150, 150); shape2.Text = "Go to" + Environment.NewLine + bookmark.Name; shape2.Hyperlink = new NShapeHyperlink(bookmark); shape2.Ports.RemoveAt(0); shape2.Style = new NShapeStyle(103, 103); page1.Items.Add(shape2); NShape shape3 = factory.CreateShape(ENBasicShape.Rectangle); shape3.SetPinPoint(100, 400); shape3.Text = "www.nevron.com"; shape3.Hyperlink = new NShapeHyperlink("https://www.nevron.com"); shape3.Ports.RemoveAt(0); page1.Items.Add(shape3); // Page 2 NShape title2 = new NShape(); title2.Text = "Page 2"; title2.SetBounds((page2.Width - TitleWidth) / 2, 20, TitleWidth, 30); title2.TextBlock.FontSize = TitleFontSize; page2.Items.Add(title2); NShape shape4 = factory.CreateShape(ENBasicShape.Ellipse); shape4.SetPinPoint(100, 200); shape4.Text = "Go to page 1"; shape4.Hyperlink = new NShapeHyperlink(page1); shape4.Ports.RemoveAt(0); shape4.Style = new NShapeStyle(102, 102); page2.Items.Add(shape4); } #endregion #region Implementation #endregion #region Event Handlers #endregion #region Fields #endregion #region Static Methods #endregion #region Constants #endregion #region Nested Types #endregion } }

Download a fully functional C# (.cs) Shape Hyperlinks Example for WPF Solution

VB.NET Shape Hyperlinks 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
Imports System

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 - NShapeHyperlinksExample"

		' 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 drawingViewWithRibbon As NDrawingViewWithRibbon = New NDrawingViewWithRibbon()
            Dim drawingView = drawingViewWithRibbon.View

            drawingView.Document.HistoryService.Pause()
            Try
                InitDiagram(drawingView.Document)
            Finally
                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 "

This example demonstrates how to add hyperlinks to shapes. Shape hyperlinks allow you to navigate to an URL, page, shape, bookmark or to open a file. Ctrl + Click on a shape with hyperlink to navigate to the hyperlink target.

" End Function ''' ''' Gets the relevant documentation links for the example ''' ''' Public Function GetDocumentationUrls() As (String, String)() Return {("Shape Hyperlink", "https://www.nevron.com/docs/openvision/diagram-shape-hyperlink.html"), ("Shapes", "https://www.nevron.com/docs/openvision/diagram-shapes.html")} End Function Private Sub InitDiagram(drawingDocument As NDrawingDocument) Const TitleWidth As Double = 100 Const TitleFontSize As Double = 16 ' Get the drawing and the active (first) page Dim drawing = drawingDocument.Content Dim page1 = drawing.ActivePage ' Create a second page and a bookmark on it Dim page2 As NPage = New NPage() drawing.Pages.Add(page2) Dim bookmark As NBookmark = New NBookmark("MyBookmark", 0, 0, 1.5) page2.BookmarkManager.Bookmarks.Add(bookmark) Dim factory As NBasicShapeFactory = New NBasicShapeFactory() factory.DefaultSize = New NSize(160, 100) ' Page 1 Dim title1 As NShape = New NShape() title1.Text = "Page 1" title1.SetBounds((page1.Width - TitleWidth) / 2, 20, TitleWidth, 30) title1.TextBlock.FontSize = TitleFontSize page1.Items.Add(title1) Dim shape1 = factory.CreateShape(ENBasicShape.Ellipse) shape1.SetPinPoint(100, 200) shape1.Text = "Go to page 2" shape1.Hyperlink = New NShapeHyperlink(page2) shape1.Ports.RemoveAt(0) shape1.Style = New NShapeStyle(101, 101) page1.Items.Add(shape1) Dim shape2 = factory.CreateShape(ENBasicShape.SixPointStar) shape2.SetPinPoint(350, 200) shape2.Size = New NSize(150, 150) shape2.Text = "Go to" & Environment.NewLine & bookmark.Name shape2.Hyperlink = New NShapeHyperlink(bookmark) shape2.Ports.RemoveAt(0) shape2.Style = New NShapeStyle(103, 103) page1.Items.Add(shape2) Dim shape3 = factory.CreateShape(ENBasicShape.Rectangle) shape3.SetPinPoint(100, 400) shape3.Text = "www.nevron.com" shape3.Hyperlink = New NShapeHyperlink("https://www.nevron.com") shape3.Ports.RemoveAt(0) page1.Items.Add(shape3) ' Page 2 Dim title2 As NShape = New NShape() title2.Text = "Page 2" title2.SetBounds((page2.Width - TitleWidth) / 2, 20, TitleWidth, 30) title2.TextBlock.FontSize = TitleFontSize page2.Items.Add(title2) Dim shape4 = factory.CreateShape(ENBasicShape.Ellipse) shape4.SetPinPoint(100, 200) shape4.Text = "Go to page 1" shape4.Hyperlink = New NShapeHyperlink(page1) shape4.Ports.RemoveAt(0) shape4.Style = New NShapeStyle(102, 102) page2.Items.Add(shape4) End Sub #End Region #Region "Implementation" #End Region #Region "Event Handlers" #End Region #Region "Fields" #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) Shape Hyperlinks Example for WPF Solution

Related Documentation Links