tags:

views:

17

answers:

1

I am trying to add horizontal and vertical "Position" attached properties to my canvas control that allow me to set a control's position (e.g. Horizontal: Left, Right, Center).

I need a children size changed event handler so that I can adjust the position of an element whose size is changed if it's horizontal or vertical position is Center.

Is there a way that I could do this?

+1  A: 

You can try this code:

public class MyCanvas : Canvas
{
    public event EventHandler ChildDesiredSizeChanged;
    protected override void OnChildDesiredSizeChanged(UIElement child)
    {
        if (ChildDesiredSizeChanged != null) ChildDesiredSizeChanged(child, EventArgs.Empty);
        base.OnChildDesiredSizeChanged(child);
    }
}
Rikker Serg