在WPF中动态更改对象的图层 [英] Change object's layer dynamically in WPF
本文介绍了在WPF中动态更改对象的图层的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
执行时,我需要使用C#代码对GRID上的对象执行向上移动",向下移动"之类的操作,有没有可能?
I need to do something like "Move up", "Move down" with the objects on my GRID from C# code while executing, is there any possibilities?
推荐答案
您可以尝试以下代码:
private bool _isUp = false;
private void button1_Click(object sender, RoutedEventArgs e) {
if (_isUp) {
Canvas.SetZIndex(rectangle1, 1);
} else {
Canvas.SetZIndex(rectangle1, 0);
}
_isUp = !_isUp;
}
为此,我仅在示例中使用2个矩形.
I just use 2 rectangles in my sample, for this.
<Rectangle Height="100" HorizontalAlignment="Left" Margin="68,142,0,0" Name="rectangle1" Stroke="Black" VerticalAlignment="Top" Width="200" Fill="#FF9D2A2A" />
<Rectangle Height="100" HorizontalAlignment="Left" Margin="10,120,0,0" Name="rectangle2" Stroke="Black" VerticalAlignment="Top" Width="200" Fill="#FF265D80" />
这篇关于在WPF中动态更改对象的图层的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文