This project is read-only.

Labels on edges, template of edgecontrol

Oct 27, 2011 at 3:46 PM
Edited Oct 27, 2011 at 3:52 PM

I define a new control template for EdgeControl, but I cannot find out why I get the following error

"Object reference not set to an instance of an object."

Here is my code:

 

<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:GraphSharpDemo"
xmlns:graphsharp="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
xmlns:Converters="clr-namespace:GraphSharp.Converters;assembly=GraphSharp.Controls"
xmlns:WPFExtensions_AttachedBehaviours="clr-namespace:WPFExtensions.AttachedBehaviours;assembly=WPFExtensions">

<Converters:EdgeRouteToPathConverter x:Key="routeToPathConverter" />

<Style TargetType="{x:Type graphsharp:EdgeControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type graphsharp:EdgeControl}">
<Canvas>
<Path Stroke="{TemplateBinding Foreground}"
StrokeThickness="2"
MinWidth="1"
MinHeight="1"
x:Name="edgePath">
<Path.Data>
<PathGeometry>
<PathGeometry.Figures>
<MultiBinding Converter="{StaticResource routeToPathConverter}">
<Binding RelativeSource="{RelativeSource TemplatedParent}"
Path="Source.(Controls:GraphCanvas.X)" />
<Binding RelativeSource="{RelativeSource TemplatedParent}"
Path="Source.(Controls:GraphCanvas.Y)" />
<Binding RelativeSource="{RelativeSource TemplatedParent}"
Path="Source.ActualWidth" />
<Binding RelativeSource="{RelativeSource TemplatedParent}"
Path="Source.ActualHeight" />
<Binding RelativeSource="{RelativeSource TemplatedParent}"
Path="Target.(Controls:GraphCanvas.X)" />
<Binding RelativeSource="{RelativeSource TemplatedParent}"
Path="Target.(Controls:GraphCanvas.Y)" />
<Binding RelativeSource="{RelativeSource TemplatedParent}"
Path="Target.ActualWidth" />
<Binding RelativeSource="{RelativeSource TemplatedParent}"
Path="Target.ActualHeight" />
<Binding RelativeSource="{RelativeSource TemplatedParent}"
Path="RoutePoints" />
</MultiBinding>
</PathGeometry.Figures>
</PathGeometry>
</Path.Data>
</Path>
<local:EdgeLabelControl Content="{Binding Edge.Tag, RelativeSource={RelativeSource TemplatedParent}}" />
</Canvas>
</ControlTemplate>
</Setter.Value>
</Setter>
 </Style>