Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Overlay two controls

Tags:

.net

layout

wpf

I started to make some thing in WPF and I have a question. I think the answer might be easy and even obvious, but somehow...

I have two controls on a form enclosed by a grid. I want two position the second control above the first one (it's transparent). Coming from WinForms development that isn't that hard, so it won't be in WPF. But I don't get the point...

Sascha

like image 711
Sascha Avatar asked Feb 18 '09 08:02

Sascha


2 Answers

Either the Grid and Canvas controls would do what you wanted.

For most cases I'd recommend using the Grid to overlay elements, as you can also control how they resize easily. They'll stack in the order you define them (last defined at the top).

Try something like this:

<Grid>
    <Rectangle Fill="Blue"/>
    <Ellipse Fill="Red"/>
</Grid>

BTW - learning XAML is much easier to do in an interactive tool like Kaxaml.

like image 54
Drew Noakes Avatar answered Nov 15 '22 22:11

Drew Noakes


If I am getting you correctly , just put the control in the reverse order inside the Grid. The order determines the Z-Index of the control

  <Grid>
    <c:ControlFirst/>
    <c:ControlSecond/>        
  </Grid>
like image 37
Jobi Joy Avatar answered Nov 16 '22 00:11

Jobi Joy