Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic More questions about the Xamarin Diagramming component (Read 1331 times)
dpru2
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Feb 2nd, 2021
More questions about the Xamarin Diagramming component
Apr 16th, 2021 at 1:38pm
Print Post  
Thanks for all the help in my previous post. I have another question! What is the correct way to programmatically create a diagram and assign it to a view?

Up until this point, I have created my Diagram in XAML like this:

Code
Select All
<diag:DiagramView x:Name="diagramView" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand">
    <diag:Diagram x:Name="diagram" Bounds="0, 0, 2000, 2000" />
</diag:DiagramView>
 



Then, in the initialization code of the page, I have some simple code like this to add a node to the diagram:

Code
Select All
ShapeNode my_node = new ShapeNode(diagram);
my_node.Bounds = new Rectangle(10, 20, 40, 30);
diagram.Nodes.Add(my_node);

diagram.Behavior = MindFusion.Diagramming.Behavior.PanAndModify;
diagram.RouteLinks = true;
diagram.AlignToGrid = true;
diagram.ShowGrid = true;
diagram.GridSizeX = 10;
diagram.GridSizeY = 10;
diagram.GridStyle = GridStyle.Lines;
diagram.ShowAnchors = ShowAnchors.Always;
diagram.SnapToAnchor = SnapToAnchor.OnCreateOrModify;
 



The above code works. However, when I change the code to try to do creation/assignment of the Diagram programmatically, it no longer works. Here is an example that does not work. The XAML now looks like this:

Code
Select All
<diag:DiagramView x:Name="diagramView" HorizontalOptions="FillAndExpand" VerticalOptions="FillAndExpand" />
 



And the C# looks like this:

Code
Select All
public partial class MainPage : ContentPage
{
    private Diagram diagram = new Diagram();

    public MainPage()
    {
        InitializeComponent();

        ShapeNode my_node = new ShapeNode(diagram);
        my_node.Bounds = new Rectangle(10, 20, 40, 30);
        diagram.Nodes.Add(my_node);

        diagram.Bounds = new Rectangle(0, 0, 2000, 2000);

        diagram.Behavior = MindFusion.Diagramming.Behavior.PanAndModify;
        diagram.RouteLinks = true;
        diagram.AlignToGrid = true;
        diagram.ShowGrid = true;
        diagram.GridSizeX = 10;
        diagram.GridSizeY = 10;
        diagram.GridStyle = GridStyle.Lines;
        diagram.ShowAnchors = ShowAnchors.Always;
        diagram.SnapToAnchor = SnapToAnchor.OnCreateOrModify;

        diagramView.Diagram = diagram;
    }
}
 



Any suggestions on how to properly programmatically assign the Diagram to the DiagramView?

Edited:
I have noticed that in the examples online, y'all do something like this:

Code
Select All
diagram = diagramView.Diagram;
 



So you are effectively letting DiagramView initialize its own Diagram object, and then you are using that one. I have tested that, and technically it does work, but unfortunately I can't do that for my use case. In my use case I want to be able to swap in and out Diagram objects to a DiagramView.

  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3153
Joined: Oct 19th, 2005
Re: More questions about the Xamarin Diagramming component
Reply #1 - Apr 19th, 2021 at 10:59am
Print Post  
Hi,

Assignment should work with this build -
https://mindfusion.eu/_temp/MindFusion.Diagramming.Xamarin.zip

Regards,
Slavcho
Mindfusion
  
Back to top
 
IP Logged
 
dpru2
YaBB Newbies
*
Offline


I Love MindFusion!

Posts: 19
Joined: Feb 2nd, 2021
Re: More questions about the Xamarin Diagramming component
Reply #2 - Apr 19th, 2021 at 1:20pm
Print Post  
It works. Thank you!
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint