I am currently designing a system, (my first in WPF) and i am looking to bind properties of my custom control to elements set within the control-style.
<Style TargetType="{x:Type c:Connection}">
<Setter Property="SnapsToDevicePixels" Value="true"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type c:Connection}">
<Grid DataContext="{Binding RelativeSource={RelativeSource TemplatedParent}}">
<Line Stroke="Red" X1="90" X2="90" Y1="90" Y2="5"/>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
I am looking to bind the elements of the Line (X1/2 Y1/2) to properties within my Connection Control. However, as soon as i add a connection element (in code, even without binding), i get a Type Initialization Error. My Connection class is as follows:
public class Connection : Control
{
public Connector StartElement { get; set; }
public Connector EndElement { get; set; }
#region Properties
#endregion
}
And I Initialize as follows: Connection con = new Connection(); (and then i add it to the canvas).
How can i bind the coordinates to a the Points that are in Connector? (ex StartElement.GetXPosition());
Kind Regards Tom