I have followed the samples to get a working xamNetworkNode on screen. I modified the "ConnectionModel" to include an property for an enumeration "ConnectionType". Based on this enumeration I would like to style the line differently.
In the post: "http://blogs.infragistics.com/blogs/atanas_dyulgerov/archive/2011/11/11/new-features-in-xamnetworknode.aspx" it states:
"In addition to those settings you can find a property called DefineConnectionCallback in the XamNetworkNode (if you use it here it will have global effect) or in the instance of a specific connection from the Connections collection of the XamNetworkNode (if you want to do a connection specific setting). This property can be set to a method that returns a Path object. This is how you can modify the form of the connection. It will no longer be a straight line, but it will have the Path you have returned in the callback."
Is there a sample somewhere of how this DefineConnectionCallback works? How can I style the line based on a property coming from the ConnectionModel?
Kind Regards,
Daniel
Hello Daniel,
Thank you for your post. I have been looking into it and I created a sample project for you, demonstrating how the DefineConnectionCallback works. Please let me know if this helps you or you need further assistance on this matter.
Looking forward for your reply.
Thanks much for the sample. From that I was able to create a way to bind to properties via the the code below:
Public Sub New()
InitializeComponent()
networkNodeControl.DefineConnectionCallback = AddressOf FormatConnections
End Sub
Public Function FormatConnections(ByVal connection As NetworkNodeConnection, ByVal sp As Point, ByVal tp As Point, ByVal osp As Point, ByVal otp As Point) As Path
Dim connectionModel As ConnectionModel = TryCast(connection.Data, ConnectionModel)
Dim myPath As Path = New Path()
myPath.DataContext = connectionModel
myPath.Data = New LineGeometry(tp, sp)
myPath.Style = FindResource("ConnectionStyle")
Return myPath
End Function <Style x:Key="ConnectionStyle" TargetType="{x:Type Path}">
<Setter Property="Stroke" Value="{Binding ConnectionType, Converter={StaticResource ColorConverter}}"/>
<Setter Property="Visibility" Value="{Binding IsVisible, Converter={StaticResource TrueToVisibleConverter}}"/>
</Style> This raises new questions. The only way I have found to have the callback invoked is to call "networkNodeControl.UpdateNodeArrangement()". What triggers the callback? Can I invoke the callback without having all of the nodes update to a new layout?
Thank you for your feedback. I am glad that you resolved your issue and I believe that other community members may benefit from this as well. Also I can say that the DefineConnectionCallback is called when some of the Nodes changes its position because the Path should be redrawn.
Thanks again.