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" />
精彩评论