0

I need to display a UserControl over the screen, o top of everything.

With the following code UserControl show content under ContentGrid.

How do I place UserControl in foreground?


Main.xaml

<Grid x:Name="LayoutRoot">
    <local:AdvertisementsFullScreen>
    </local:AdvertisementsFullScreen>

GibboK
  • 71,848
  • 143
  • 435
  • 658

3 Answers3

0

ZIndex

http://msdn.microsoft.com/en-us/library/system.windows.controls.panel.zindex.aspx

<Grid>
<Grid Panel.ZIndex="1">
    <Rectangle Fill="Blue" Width="50" Height="50" Panel.ZIndex="1" />
    <Rectangle Fill="Red" Width="50" Height="50" Panel.ZIndex="0" />
</Grid>
<Grid Panel.ZIndex="0">
    <Rectangle Fill="Green" Width="50" Height="50" Panel.ZIndex="0" />
    <Rectangle Fill="Yellow" Width="50" Height="50" Panel.ZIndex="0" />
</Grid>

Jack Malkovich
  • 786
  • 13
  • 33
0

Using

<UserControl Panel.ZIndex="100" />

On my UserControl, solved my problem.

GibboK
  • 71,848
  • 143
  • 435
  • 658
0

There are different ways to achieve what you're after. One way would be to set the Panel.ZIndex attached property on it:

<local:AdvertisementsFullScreen Panel.ZIndex="10" />

Another is just to declare it underneath other controls on the XAML page:

<local:AdvertisementsFullScreen /> 
<local:AdvertisementsFullScreen /> <!-- This one is on top -->

A third, perhaps more suitable method is to use the Adorner Class. The Adorner Layer is a visual layer above the normal layer where UI elements are displayed. While it is not normally used to display whole UserControls, it is possible. Please see the answer to the WPF adorner with controls inside question here on Stack Overflow for further information on this.

Community
  • 1
  • 1
Sheridan
  • 68,826
  • 24
  • 143
  • 183