Hi Walter,
I modified another CustomControl I found on the Internet to help you reproduce the problem. If you put this in a template for a node and change the Pens Thickness in OnRender to 0.0 you should see the effect.
using System;
using System.Windows;
using System.Windows.Media;
namespace My.Controls
{
public class MyElement : FrameworkElement
{
private static FrameworkPropertyMetadata childMetadata =
new FrameworkPropertyMetadata(null,
FrameworkPropertyMetadataOptions.AffectsParentArrange,
OnChildChanged);
public static void OnChildChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
MyElement thisElement = obj as MyElement;
if (thisElement == null)
throw new Exception("Child property must be attached to MyElement");
// Remove old one
Visual oldChild = e.OldValue as Visual;
if (oldChild != null)
{
thisElement.RemoveVisualChild(oldChild);
thisElement.RemoveLogicalChild(oldChild);
}
// Attach new one
Visual newChild = e.NewValue as Visual;
if (newChild != null)
{
thisElement.AddVisualChild(newChild);
thisElement.AddLogicalChild(newChild);
}
}
public static readonly DependencyProperty ChildProperty =
DependencyProperty.RegisterAttached("Child", typeof(UIElement),
typeof(MyElement), childMetadata);
public static void SetChild(DependencyObject depObj, UIElement value)
{
depObj.SetValue(ChildProperty, value);
}
protected override int VisualChildrenCount
{
get
{
UIElement childElement = (UIElement)GetValue(ChildProperty);
return childElement != null ? 1 : 0;
}
}
protected override Visual GetVisualChild(int index)
{
// (ignoring index)
return (UIElement)GetValue(ChildProperty);
}
protected override Size MeasureOverride(Size availableSize)
{
UIElement childElement = (UIElement)GetValue(ChildProperty);
if (childElement != null)
childElement.Measure(availableSize);
// "X" and child both use all of the available space
return availableSize;
}
protected override Size ArrangeOverride(Size finalSize)
{
UIElement childElement = (UIElement)GetValue(ChildProperty);
if (childElement != null)
childElement.Arrange(new Rect(new Point(0.0, 0.0), finalSize));
return finalSize;
}
// Render a big "X"
protected override void OnRender(DrawingContext dc)
{
//dc.DrawLine(new Pen(Brushes.Blue, 2.0),
// new Point(0.0, 0.0),
// new Point(ActualWidth, ActualHeight));
//dc.DrawLine(new Pen(Brushes.Green, 2.0),
// new Point(ActualWidth, 0.0),
// new Point(0.0, ActualHeight));
dc.DrawRectangle(Brushes.Blue, new Pen(Brushes.Green, 0.01), new Rect(new Point(0,0), new Point(ActualWidth, ActualHeight)));
}
}
}