Page Index Toggle Pages: 1 Send TopicPrint
Normal Topic Add & remove icons for a diagram node (Read 2471 times)
Mathias Z.
YaBB Newbies
*
Offline


DiagramLite is cool!

Posts: 5
Joined: Sep 27th, 2010
Add & remove icons for a diagram node
Sep 27th, 2010 at 9:03am
Print Post  
I am excited about the new SpringLayoutTraits.frozen functionality.
To indicate for a user if a node in the diagram is "frozen" or not, I want to show a "pin" or "unpin" icon on the individual node. Important: as the user can change if a node is frozen or not, the icon on the node must be changed (replaced) at runtime.
I am successful in setting the image element of the node at runtime, but I need a better way (because first of all the icon looks very blurred since I have to make it very small, secondly I plan to add further icons to a diagram node at runtime, indicating other properties).

I create the diagram nodes following the approach you demonstrated in Tutorial 3 (defining a ControlTemplate). I was successful in "drawing" the icon in XAML and add it to the ControlTemplate (as a subordinate canvas). But I didn't find a way how to hide/remove/replace this "icon" at runtime.
I am programming in C# (but have to admit that I am not a C# expert).

Can you help?

Thanks a lot in advance

Mathias
  

Mathias
Back to top
 
IP Logged
 
Stoyo
God Member
*****
Offline


MindFusion support

Posts: 13230
Joined: Jul 20th, 2005
Re: Add & remove icons for a diagram node
Reply #1 - Sep 27th, 2010 at 11:52am
Print Post  
Hi,

Perhaps the easiest way to do that is to add both the pinned and unpinned drawings to the template, and bind either the Opacity or Visibility property for one of them to a custom bool 'Pinned' property of the node class. To bind double or enum to boolean, you will have to specify an IValueConverter in the binding expression. The Pinned property setter would also set LayoutTraits[Frozen] if it's a CLR property, or do that from the OnChanged callback if it's a dependency property.

Another possibility is to define a visual state group with two states - Pinned and Unpinned - and call VisualStateManager.GoToState from the property setter or change callback. Then you could set a different Path or Canvas as content of the pin-button container depending on the current state, by adding ObjectAnimationUsingKeyFrames to the VisualStateManager storyboard.

Yet another possibility is to get a reference to the Canvas from an OnApplyTemplate override, and dynamically change the canvas content when the Pinned property changes...

I hope that helps,
Stoyan
  
Back to top
 
IP Logged
 
Mathias Z.
YaBB Newbies
*
Offline


DiagramLite is cool!

Posts: 5
Joined: Sep 27th, 2010
Re: Add & remove icons for a diagram node
Reply #2 - Sep 27th, 2010 at 4:53pm
Print Post  
Hello Stoyan,

thanks for this very speedy answer. I will check out your suggestions and provide feedback. It may take a couple of days...

Cheers

Mathias
  

Mathias
Back to top
 
IP Logged
 
Mathias Z.
YaBB Newbies
*
Offline


DiagramLite is cool!

Posts: 5
Joined: Sep 27th, 2010
Re: Add & remove icons for a diagram node
Reply #3 - Oct 2nd, 2010 at 10:40pm
Print Post  
Hello Stoyan,

I followed your advice and implemented a dependency property. It took me a while to understand how to do it right, but now it works great and does exactly what I wanted it to do.
Thanks a lot Smiley
  

Mathias
Back to top
 
IP Logged
 
Page Index Toggle Pages: 1
Send TopicPrint