Create a new Xamarin Forms application or open your existing application.
Android
If targeting Android:
- Add a reference to MindFusion.Diagramming.dll, MindFusion.Diagramming.Android.dll, MindFusion.Common.dll and MindFusion.Common.Android.dll to your solution's Android project.
- In MainActivity.cs, call MindFusion.Diagramming.Android.Platform.Init after Xamarin initialization code.
C#
Copy Code
|
---|
protected override void OnCreate(Bundle savedInstanceState) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar;
base.OnCreate(savedInstanceState);
Xamarin.Essentials.Platform.Init(this, savedInstanceState); global::Xamarin.Forms.Forms.Init(this, savedInstanceState); MindFusion.Diagramming.Android.Platform.Init();
LoadApplication(new App()); } |
iOS
If targeting iOS:
- Add a reference to MindFusion.Diagramming.dll, MindFusion.Diagramming.iOS.dll, MindFusion.Common.dll and MindFusion.Common.iOS.dll to your solution's iOS project.
- In AppDelegate.cs, call MindFusion.Diagramming.iOS.Platform.Init after Xamarin initialization code.
C#
Copy Code
|
---|
public override bool FinishedLaunching(UIApplication app, NSDictionary options) { global::Xamarin.Forms.Forms.Init(); MindFusion.Diagramming.iOS.Platform.Init();
LoadApplication(new App());
return base.FinishedLaunching(app, options); } |
Universal Windows
If targeting UWP:
- Add a reference to MindFusion.Diagramming.dll, MindFusion.Diagramming.Universal.dll, MindFusion.Common.dll and MindFusion.Common.Universal.dll assemblies to your solution's UWP project.
- In App.xaml.cs, call MindFusion.Diagramming.Universal.Platform.Init after Xamarin initialization code.
C#
Copy Code
|
---|
Frame rootFrame = Window.Current.Content as Frame;
// Do not repeat app initialization when the Window already has content, // just ensure that the window is active if (rootFrame == null) { // Create a Frame to act as the navigation context and navigate to the first page rootFrame = new Frame();
rootFrame.NavigationFailed += OnNavigationFailed;
Xamarin.Forms.Forms.Init(e); MindFusion.Diagramming.Universal.Platform.Init(); ... } |
Shared project
- Add a reference to MindFusion.Diagramming.dll and MindFusion.Common.dll to the shared Xamarin UI project.
- Open the content page xaml file and add diagram namespace definition and DiagramView instance:
Xaml
Copy Code
|
---|
<?xml version="1.0" encoding="utf-8" ?> <ContentPage xmlns="http://xamarin.com/schemas/2014/forms" xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" xmlns:diag="clr-namespace:MindFusion.Diagramming;assembly=MindFusion.Diagramming" xmlns:local="clr-namespace:MinApp" x:Class="MinApp.MainPage">
<diag:DiagramView x:Name="diagramView" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
<diag:Diagram x:Name="diagram" Bounds="0, 0, 2000, 2000" />
</diag:DiagramView>
</ContentPage> |
- In C# code-behind file you can now access members of the Diagram class -
C#
Copy Code
|
---|
public MainPage() { InitializeComponent();
var node1 = diagram.Factory.CreateShapeNode(10, 20, 40, 30); node1.Text = "Hello,";
var node2 = diagram.Factory.CreateShapeNode(20, 70, 40, 30); node2.Text = "World!";
diagram.Factory.CreateDiagramLink(node1, node2); } |
Running
From the context menu of the platform project you wish to run select 'Set as StartUp project'. In CPU and target device drop down boxes of Visual Studio select the appropriate device and hit the Run toolbar icon. If there are no compilation or deployment errors, you should see this simple diagram:
