Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Yes, you can use the Popup control, but you need to set the Child property to a content control which covers the full App window AND resizes when the window size is changed. It is not hard to create your own.</p> <p>Create a Templated Control based on a ContentControl:</p> <pre class="lang-cs prettyprint-override"><code>public sealed class PopoverView : ContentControl { public PopoverView() { this.DefaultStyleKey = typeof(PopoverView); Loaded += OnLoaded; Unloaded += OnUnloaded; } /// &lt;summary&gt; /// Measure the size of this control: make it cover the full App window /// &lt;/summary&gt; protected override Size MeasureOverride(Size availableSize) { Rect bounds = Window.Current.Bounds; availableSize = new Size(bounds.Width, bounds.Height); base.MeasureOverride(availableSize); return availableSize; } private void OnLoaded(object sender, RoutedEventArgs e) { Window.Current.SizeChanged += OnSizeChanged; } private void OnSizeChanged(object sender, WindowSizeChangedEventArgs e) { InvalidateMeasure(); } private void OnUnloaded(object sender, RoutedEventArgs e) { Window.Current.SizeChanged -= OnSizeChanged; } } </code></pre> <p>Add this code to the Generic.xaml:</p> <pre class="lang-xaml prettyprint-override"><code>&lt;SolidColorBrush x:Key="PopoverViewBackgroundThemeBrush"&gt;White&lt;/SolidColorBrush&gt; &lt;!-- Semi-transparant black brush to cover the background: --&gt; &lt;SolidColorBrush x:Key="PopoverViewOverlayThemeBrush"&gt;#80000000&lt;/SolidColorBrush&gt; &lt;Style TargetType="local:PopoverView"&gt; &lt;Setter Property="Template"&gt; &lt;Setter.Value&gt; &lt;ControlTemplate TargetType="local:PopoverView"&gt; &lt;Grid&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="*" /&gt; &lt;RowDefinition Height="Auto" /&gt; &lt;RowDefinition Height="*" /&gt; &lt;/Grid.RowDefinitions&gt; &lt;Border Grid.Row="0" Background="{StaticResource PopoverViewOverlayThemeBrush}" /&gt; &lt;Border Grid.Row="1" Child="{TemplateBinding Content}" Background="{StaticResource PopoverViewBackgroundThemeBrush}" /&gt; &lt;Border Grid.Row="2" Background="{StaticResource PopoverViewOverlayThemeBrush}" /&gt; &lt;/Grid&gt; &lt;/ControlTemplate&gt; &lt;/Setter.Value&gt; &lt;/Setter&gt; &lt;/Style&gt; </code></pre> <p>Now you can create a UserControl with the PopoverView as content. Example:</p> <pre class="lang-xaml prettyprint-override"><code>&lt;UserControl x:Class="PopoverCustomControlTest.MyUserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:local="using:PopoverCustomControlTest" xmlns:custom="using:MyCustomControls" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" mc:Ignorable="d"&gt; &lt;custom:PopoverView&gt; &lt;!-- Create your own dialog here instead of this simple button --&gt; &lt;Button Content="Close PopoverView" Click="Button_Click_1" Background="Black" HorizontalAlignment="Center" Margin="40" /&gt; &lt;/custom:PopoverView&gt; &lt;/UserControl&gt; </code></pre> <pre class="lang-cs prettyprint-override"><code>public sealed partial class MyUserControl1 : UserControl { private Popup popup; public MyUserControl1(Popup popup) { if (popup == null) throw new ArgumentNullException("popup"); this.popup = popup; this.InitializeComponent(); } private void Button_Click_1(object sender, RoutedEventArgs e) { this.popup.IsOpen = false; } } </code></pre> <p>And show it when you need it:</p> <pre class="lang-cs prettyprint-override"><code>Popup popup = new Popup(); popup.Child = new MyUserControl1(popup); popup.IsOpen = true; </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload