Hi Stoyo,
maybe I was a little simple-hearted regarding the Template.
So I worked out an own DataTemplate for testing purpose that is related to MyTemplatedNode:
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MindFusionProject">
<Style TargetType="local:MyTemplatedNode">
<Setter Property="Template">
<Setter.Value>
<DataTemplate DataType="local:MyTemplatedNode">
<Border
BorderBrush="{Binding Stroke}"
BorderThickness="{Binding StrokeThickness}"
Background="{Binding Brush}">
</Border>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
The corresponding class looks like:
namespace MindFusionProject
{
public class MyTemplatedNode: TemplatedNode
{
static MyTemplatedNode()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(MyTemplatedNode), new FrameworkPropertyMetadata(typeof(MyTemplatedNode)));
}
public MyTemplatedNode(MyTemplatedNode prototype)
: base(prototype)
{
}
public Brush BorderBrush
{
get { return (Brush)GetValue(BorderBrushProperty); }
set { SetValue(BorderBrushProperty, value); }
}
public static readonly DependencyProperty BorderBrushProperty = DependencyProperty.Register(
"BorderBrush",
typeof(Brush),
typeof(MyTemplatedNode),
new FrameworkPropertyMetadata(Brushes.Green, FrameworkPropertyMetadataOptions.AffectsRender));
public double BorderThickness
{
get { return (double)GetValue(BorderThicknessProperty); }
set { SetValue(BorderThicknessProperty, value); }
}
public static readonly DependencyProperty BorderThicknessProperty = DependencyProperty.Register(
"BorderThickness",
typeof(double),
typeof(MyTemplatedNode),
new PropertyMetadata(1.0));
public Brush Background
{
get { return (Brush)GetValue(BackgroundProperty); }
set { SetValue(BackgroundProperty, value); }
}
public static readonly DependencyProperty BackgroundProperty = DependencyProperty.Register(
"Background",
typeof(Brush),
typeof(MyTemplatedNode),
new FrameworkPropertyMetadata(Brushes.Green, FrameworkPropertyMetadataOptions.AffectsRender));
public MyTemplatedNode()
{
//Stroke = System.Windows.Media.Brushes.Red;
//StrokeThickness = 5.0;
//Brush = System.Windows.Media.Brushes.Green;
BorderBrush = Brushes.Red;
BorderThickness = 5.0;
Background = Brushes.Green;
}
}
private void diagram_Loaded(object sender, RoutedEventArgs e)
{
var node = new MyTemplatedNode
{
Bounds= new Rect (200,200,200,200),
BorderBrush = Brushes.Red,
BorderThickness = 5.0,
Background = Brushes.Green,
//Stroke = Brushes.Red,
//StrokeThickness = 5.0,
//Brush = Brushes.Green,
};
diagram.Nodes.Add(node);
}
}
Just for testing I want to see a green Rect with a red border of 5.0 thickness.
But I always get a white Rect with a black border of 1.0 thickness unless I uncomment the
three lines in the diagram_Loaded where I set the properties directly instead of using the bounded methods.
Regards,
Pontius