brain_pusher
brain_pusher

Reputation: 1527

How to set Z index when using WPF DrawingContext?

How to set Z-Index for a drawing object when using DrawingContext.DrawXXX() methods?

Upvotes: 4

Views: 3661

Answers (1)

kyrylomyr
kyrylomyr

Reputation: 12632

The object that was drawn last will have a higher Z index. You can't change index of an already drawn objects. The only way is to draw in another order.

If you are using WPF (as you placed that tag), you can use, for example, Canvas control. Then you just create shapes you need like

Polyline obj = new Polyline(); //...
// ... set properties of obj

and add them to Canvas UIElementCollection:

yourCanvasName.Children.Add(obj);
//or
yourCanvasName.Children.Insert(i, obj);

First items of that collection will have higher Z index. You will also get advantages in that way: no need to redraw on window changes, can anytime move objects and change order.

Upvotes: 5

Related Questions