Page Index Toggle Pages: [1] 2  Send TopicPrint
Hot Topic (More than 10 Replies) add a custom property for ShapeNode (Read 8296 times)
kelum
Full Member
***
Offline


I Love MindFusion!

Posts: 100
Joined: Mar 25th, 2017
add a custom property for ShapeNode
Apr 28th, 2017 at 5:08am
Print Post  
In mindfusion how to add custom ShapeNode property ?

Ex: add following property

ID 
Name
Type
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: add a custom property for ShapeNode
Reply #1 - Apr 28th, 2017 at 8:37am
Print Post  
Id and Name properties are already available, derived from DiagramItem and FrameworkElement respectively. Name is not serialized by built-in code though. You can add custom properties like Type as shown in IconNodes, Tutorial 3 & 4 sample projects.

Another approach without creating custom node class is shown in SiteMap sample project - it defines properties in a separate class and assigns its instance to standard ShapeNode's Tag property.
  
Back to top
 
IP Logged
 
kelum
Full Member
***
Offline


I Love MindFusion!

Posts: 100
Joined: Mar 25th, 2017
Re: add a custom property for ShapeNode
Reply #2 - Apr 28th, 2017 at 9:49am
Print Post  
can you give the direct link for "Tutorial 3 & 4 sample projects." ?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: add a custom property for ShapeNode
Reply #3 - Apr 28th, 2017 at 10:00am
Print Post  
If you've run the diagram's installer you can find sample projects under C:\Program Files (x86)\MindFusion\MindFusion.Diagramming for WPF\Samples\Source code\ folder. You can also download individual sample projects here -
http://mindfusion.eu/wpf-diagram-samples.html

Regards,
Slavcho
  
Back to top
 
IP Logged
 
kelum
Full Member
***
Offline


I Love MindFusion!

Posts: 100
Joined: Mar 25th, 2017
Re: add a custom property for ShapeNode
Reply #4 - Apr 29th, 2017 at 8:38am
Print Post  
in tutorial 3 and 4 i cant find places where its adding new property ? can you specifically mention the places I need to change to add a new custom property to this shapenode ?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: add a custom property for ShapeNode
Reply #5 - May 1st, 2017 at 5:46am
Print Post  
You can find Title, FullName and Image properties created in OrgChartNode.cs. Also check the help topic here -
http://www.mindfusion.eu/onlinehelp/wpfdiagram/index.htm?CC_Tutorial_3__Create_a...
  
Back to top
 
IP Logged
 
kelum
Full Member
***
Offline


I Love MindFusion!

Posts: 100
Joined: Mar 25th, 2017
Re: add a custom property for ShapeNode
Reply #6 - May 2nd, 2017 at 3:40am
Print Post  
Actually I'm trying to add new property for `ShapeNode` not to Create a Custom Node Type ?

is that possible to add new property for `ShapeNode` ? if yes, can you give reference or please mention it step by step
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: add a custom property for ShapeNode
Reply #7 - May 2nd, 2017 at 5:37am
Print Post  
You could either add your properties to a struct and assign its instance to node.Tag as shown in SiteMap example, or use WPF attached properties -
https://msdn.microsoft.com/en-us/library/ms749011(v=vs.110).aspx
  
Back to top
 
IP Logged
 
kelum
Full Member
***
Offline


I Love MindFusion!

Posts: 100
Joined: Mar 25th, 2017
Re: add a custom property for ShapeNode
Reply #8 - May 2nd, 2017 at 5:42am
Print Post  
okay I wish to follow this path `add new properties to a struct and assign its instance to node`

can you mention steps it with a sample ?
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: add a custom property for ShapeNode
Reply #9 - May 2nd, 2017 at 5:52am
Print Post  
See https://mindfusion.eu/samples/wpf/diagram/SiteMap.CS.zip

It defines a PageProps structure in MainWindow.xaml.cs and keeps there values that must be associated with nodes. You can see Tag assigned in OnNodeCreated handler. If you need the custom values saved in XML, also check SerializeTag and DeserializeTag handlers.
  
Back to top
 
IP Logged
 
kelum
Full Member
***
Offline


I Love MindFusion!

Posts: 100
Joined: Mar 25th, 2017
Re: add a custom property for ShapeNode
Reply #10 - May 2nd, 2017 at 7:55am
Print Post  
is it possible to initiate this property once this ShapeNode adding to shaplist in constructor ?

public LayoutWindow()
{
InitializeComponent();
shapeList.Items.Add(new ShapeNode { Bounds = new Rect(0, 0, 50, 50), Tag.NewProperty = NewPropertyValue});
}
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: add a custom property for ShapeNode
Reply #11 - May 2nd, 2017 at 8:39am
Print Post  
Try something like this -

Code
Select All
new ShapeNode
{
    ....
    Tag = new MyTag { NewProperty = NewPropertyValue },
    ....
} 

  
Back to top
 
IP Logged
 
kelum
Full Member
***
Offline


I Love MindFusion!

Posts: 100
Joined: Mar 25th, 2017
Re: add a custom property for ShapeNode
Reply #12 - May 2nd, 2017 at 8:58am
Print Post  
but then that Node Property not listing under following method

for (int i = 0; i < 2; i++)
{
var node = diagram.Factory.CreateShapeNode(90, 100 + i * 70, 60, 30, Shapes.Rectangle);
node.RotationAngle = 45;

//This is not listing
node.Type = "NewTypeValue";
}

for list under CreateShapeNode

do I need to do following ?


    [Serializable]
    internal class ShapeNodeCustomProperties
    {
        internal string NewProperty { get; set; }
    }


    ShapeNodeCustomProperties newprop = new ShapeNodeCustomProperties();

     for (int i = 0; i < 3; i++)
    {
          var node = diagram.Factory.CreateShapeNode(90, 100 + i * 70, 60, 30, Shapes.Rectangle);
          node.RotationAngle = 45;               
          newprop.Type = "NewTypeValue";
          node.Tag = newprop.Type;               
     }
  
Back to top
 
IP Logged
 
Slavcho
YaBB Moderator
*****
Offline


tech.support

Posts: 3152
Joined: Oct 19th, 2005
Re: add a custom property for ShapeNode
Reply #13 - May 2nd, 2017 at 9:04am
Print Post  
It's a property of the tag structure and not of the node, you will need to set your custom values through Tag -

node.Tag = new MyTag { Type =  "NewTypeValue" }
  
Back to top
 
IP Logged
 
kelum
Full Member
***
Offline


I Love MindFusion!

Posts: 100
Joined: Mar 25th, 2017
Re: add a custom property for ShapeNode
Reply #14 - May 2nd, 2017 at 9:06am
Print Post  
okay thanks Smiley is this need to serialize and de-serialize also ?
  
Back to top
 
IP Logged
 
Page Index Toggle Pages: [1] 2 
Send TopicPrint