user2261524
user2261524

Reputation: 415

Get Event for changing width of canvas

When I change my canvas width on runtime, can I get an Event when the width of my canvas change ?

Changing my width on runtime trough:

myCanvas.width = myCanvas.width + 1;

Is there an event like:

private void CanvasWidthChanged(object sender, WidthChangedEventArgs e)
{

}

Upvotes: 1

Views: 3259

Answers (3)

honzakuzel1989
honzakuzel1989

Reputation: 2520

You can create own class inherited from Canvas and proces changed of size in this class. Something like

public class DXFCanvas : Canvas
{
    protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
    {
        base.OnRenderSizeChanged(sizeInfo);

        // Your action ...
        // (SizeChangedInfo contains old and new size)
    }
}

Upvotes: 0

Andy
Andy

Reputation: 4097

Use the SizeChanged Event.

myCanvas.SizeChanged += myCanvas_SizeChanged;

private void myCanvas_SizeChanged(object sender, SizeChangedEventArgs e)
{

}

Upvotes: 4

Patrick
Patrick

Reputation: 17973

You should be able to use the SizeChanged event.

There's a WidthChanged property in the event args that you can use to see if the width changed.

Upvotes: 3

Related Questions