Change object's layer dynamically in WPF

天涯浪子 提交于 2019-12-25 01:18:23

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/6092836/change-objects-layer-dynamically-in-wpf

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