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

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

<ContentDialog

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:

Margin="200,100,0,0"

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;

	//************************************************************************
	//************************************************************************
	//********** TOUCH OUTSIDE OF CONTENT DIALOG POPUP TO CLOSES IT **********
	//************************************************************************
	//************************************************************************
	protected override void OnApplyTemplate()
	{
		base.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;
	}
Feel free to comment if you can add help to this page or point out issues and solutions you have found. I do not provide support on this site, if you need help with a problem head over to stack overflow.

Comments

Your email address will not be published. Required fields are marked *