how can we change zindex of a silverlight control programmatically?

与世无争的帅哥 提交于 2019-12-12 11:08:54

问题


I have some controls added in a stackpanel programmatically. What i want to do is that i want one of the controls in this stackpanel to be placed over another control. Specifically, I want to place button over an image in this stack panel. I couldn't find zindex property in c# codebehind. Although it seems very simple problem but i am unable to find any clue to solve this problem. Anyone please......??


回答1:


Try placing all your controls on Canvas. Then you can set Zindex with:

this.controlName.SetValue(Canvas.ZIndexProperty, 10d);



回答2:


Only the Canvas panel supports a ZIndex property. Stackpanel doesn't because each item is placed one after the other in the panel so they shouldn't overlap each other. This can be a little annoying at times when you have animated transforms moving the items about because the previous assumption isn't actually true.

In general though if you need to place items in a visual stack the Stackpanel isn't the right place for it. Perhaps a Canvas or you could use a Grid where the oridinal position of a element determines its "zorder" in a cell.




回答3:


From xaml:

<StackPanel Canvas.ZIndex="1">
</StackPanel>


来源:https://stackoverflow.com/questions/1802108/how-can-we-change-zindex-of-a-silverlight-control-programmatically

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!