wpf C#更改图层位置

| 我有这样的XML代码:
<rectangle />
<textbox />
<button Name=\"PositionChanger\" />
如果单击名称为PositionChanger的按钮,则矩形应移动到TextBox的前面,而TextBox则应移动到矩形的后面。 请帮助我使用C#以编程方式创建它。     
已邀请:
您可以使用
Zindex
属性来实现此目的。
//initially text box would be on top because Zindex is set to 1 and Rectangle would be behind it
<TextBox x:Name=\"text\" Panel.ZIndex=\"1\" />
<Rectangle x:Name=\"rect\" Panel.ZIndex=\"0\"/>
内部按钮单击事件执行此操作
  Panel.SetZIndex(text, 0);
  Panel.SetZIndex(rect,1);
现在矩形将在顶部,文本框将在矩形之后     

要回复问题请先登录注册