开发者

How to set Z index when using WPF DrawingContext?

开发者 https://www.devze.com 2023-02-14 16:16 出处:网络
How to set Z-Index for a drawing object when us开发者_如何学Pythoning DrawingContext.DrawXXX() methods?The object that was drawn last will have a higher Z index. You can\'t change index of an already

How to set Z-Index for a drawing object when us开发者_如何学Pythoning DrawingContext.DrawXXX() methods?


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号