开发者

Change object's layer dynamically in WPF

I need to do something like "Move up", "Move down" with the objects on my GRID from C# code while executing, is there any possibi开发者_如何学Clities?


You can try this code:

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;
}

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" />
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜