I was able to add design-time adorner to a WPF control, but how do I take control over those built-into the designer? (in other words, I want my function to be called when anyone drags or resizes a control using standard designer's thumbs/rubber-bands/adorners/...)
.
Below are details on what I am trying to accomplish:
I'm writing a WPF Canvas-like control that has custom rules to place and size it's children. (it should also rotate, but that's another question)
<my:MyCustomCanvas>
<my:SomeControl my:Name="child control #1" Canvas.Left="20" Canvas.Top="30"/>
<my:SomeOtherControl my:Name="child control #2" Canvas.Left="70" Canvas.Top="80"/>
</my:MyCustomCanvas>
One way to achieve this is overriding ArrangeOverride() like this:
public class CustomCanvas : Canvas
{
protected override Size ArrangeOverride(Size arrangeSize)
{
foreach (UIElement child in InternalChildren)
{
double left = child.GetValue(Canvas.LeftProperty) - this.GetValue(ActualWidthProperty) / 2;
double top = child.GetValue(Canvas.TopProperty) - this.GetValue(ActualHeightProperty) / 2;
child.Arrange(new Rect(new Point(left, top), child.DesiredSize));
}
return arrangeSize;
}
}
It works, but if you try to drag or resize a child control in the designer, it jumps to where it would have been if it was on a normal WPF Canvas (i.e. X = Left , not X = Left - Width / 2 as ArrangeOverride dictates)
It looks like I need to take control of the designer. Microsoft even provided documentation how to do that: Walkthrough: Creating a Design-time Adorner. It appears to work, however I failed to find a method to control how adorners that are built into visual studio work (those sizing thumbs that appear around a control when it is selected), only how to add new ones. Sure, I could just add few and instruct anyone not to touch standard ones, but it looks like an ugly kludge.
For the purpose of this question it is safe to assume I have access to source code (i.e. can override methods) of both canvas, and its children, although methods that only need to alter parent canvas are preferred.
Official documentation on designer extensibility looks somewhat confusing to me. I had no luck searching the matter on the web either. So any useful clues will be greatly appreciated - like books, articles, examples, reference source links, etc.