Menu > Project > Add new item > Visual C# > Content Dialog

You need to set min and max as well as the required Width and Height:


Width="355" MinWidth="355" MaxWidth="355"
Height="276" MinHeight="276" MaxHeight="276"
Setting its location on the screen

You can use the margin to do this:


Detect a touch outside of ContentDialog

A ContentDialog is placed in PopupRoot. Behind it, there is a Rectangle which dims other displayed elements and stops them being interacted with. You can use VisualTreeHelper to find it and and register a Tapped event with it so you can detect when it is tapped.

You can do this after calling ShowAsync (outside of the ContentDialog pages code) or in the ContentDialog page code as shown below:

using Windows.UI.Xaml.Shapes;

	private Rectangle ScreenBackgroundRectangle;

	protected override void OnApplyTemplate()

		//Find all of the open popups.  Normally there are 2, one for this ContentDialog and one for the background Rectangle
		var OpenPopups = VisualTreeHelper.GetOpenPopups(Window.Current);
		foreach (var OpenPopup in OpenPopups)
			if (OpenPopup.Child is Rectangle)
				ScreenBackgroundRectangle = OpenPopup.Child as Rectangle;
				ScreenBackgroundRectangle.Tapped += OnLockRectangleTapped;

	private void OnLockRectangleTapped(object sender, TappedRoutedEventArgs e)
		this.Hide();		//Close us / the ContentDialog
		ScreenBackgroundRectangle.Tapped -= OnLockRectangleTapped;
We benefit hugely from resources on the web so we decided we should try and give back some of our knowledge and resources to the community by opening up many of our company’s internal notes and libraries through mini sites like this. We hope you find the site helpful.
Please feel free to comment if you can add help to this page or point out issues and solutions you have found, but please note that we do not provide support on this site. If you need help with a problem please use one of the many online forums.


Your email address will not be published.