3

You can't define the content of a window twice, but is there a way to overlay a grid on top of another grid?

In my specific case, I am creating a chess game and I want one grid to manage the pieces and their UI, and another grid to manage the black and white squares. I want to do it this way (as opposed to using one grid with different Z indexes) because during the game I want to add Opaque Rectangles on the squares that are valid moves. If I use a separate grid, I can clear the rectangles by doing myGrid.Children.Clear() in order to clean the square-UI, but keep the pieces in place.

Another solution would be to clear all children of a specific Z Index. Is that possible?

Thanks for the help, I can post code if needed!

H.B.
  • 166,899
  • 29
  • 327
  • 400
Adam
  • 488
  • 6
  • 19
  • Currently I am using a grid and setting the Z indexes of the pieces that I want to clear to 10. Then I iterate through the children and set the opacity of the ones with Z index == 10 to 0. It is _very_ slow – Adam Sep 06 '12 at 02:44
  • I got something to work better... I am keeping track of what needs to be displayed in an Array of rectangles. Every time I need to, I update the UI based on the state of the Array. It is much much faster – Adam Sep 06 '12 at 03:00

2 Answers2

7

Overlaying one grid on top of another:

<Grid>
<Grid x:Name="grid1" />
<Grid x:Name="grid2" />
</Grid>
Erti-Chris Eelmaa
  • 25,338
  • 6
  • 61
  • 78
  • Thanks! This seems to be exactly what I wanted. I failed to encase both grids in another grid tag, so I was getting errors. – Adam Sep 06 '12 at 14:49
0

Adorners! An adorner is rendered in a layer seperate from that of the main window so you can have your chess board in one grid and the pieces in a grid contained within an adorner layer. http://www.nbdtech.com/Blog/archive/2010/06/21/wpf-adorners-part-1-ndash-what-are-adorners.aspx

Tejas Sharma
  • 3,420
  • 22
  • 35