{"id":769,"date":"2019-02-13T16:23:58","date_gmt":"2019-02-13T16:23:58","guid":{"rendered":"https:\/\/ibex.tech\/windows-iot\/?p=769"},"modified":"2019-02-13T16:23:58","modified_gmt":"2019-02-13T16:23:58","slug":"fixed-size-contentdialog","status":"publish","type":"post","link":"https:\/\/ibex.tech\/csharp\/uwp-programming-in-c\/windows-and-pages\/pages\/content-dialog-boxes\/fixed-size-contentdialog","title":{"rendered":"Fixed Size ContentDialog"},"content":{"rendered":"\n<p>Menu &gt; Project &gt; Add new item &gt; Visual C# &gt; Content Dialog <\/p>\n\n\n\n<p>You need to set min and max as well as the required Width and Height:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>&lt;ContentDialog\n\nWidth=\"355\" MinWidth=\"355\" MaxWidth=\"355\"\nHeight=\"276\" MinHeight=\"276\" MaxHeight=\"276\"<\/code><\/pre>\n\n\n\n<h5 class=\"wp-block-heading\">Setting its location on the screen<\/h5>\n\n\n\n<p>You can use the margin to do this:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>Margin=\"200,100,0,0\"<\/code><\/pre>\n\n\n\n<h4 class=\"wp-block-heading\">Detect a touch outside of ContentDialog<\/h4>\n\n\n\n<p>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.<\/p>\n\n\n\n<p>You can do this after calling ShowAsync (outside of the ContentDialog pages code) or in the ContentDialog page code as shown below:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>using Windows.UI.Xaml.Shapes;\n\n\tprivate Rectangle ScreenBackgroundRectangle;\n\n\t\/\/************************************************************************\n\t\/\/************************************************************************\n\t\/\/********** TOUCH OUTSIDE OF CONTENT DIALOG POPUP TO CLOSES IT **********\n\t\/\/************************************************************************\n\t\/\/************************************************************************\n\tprotected override void OnApplyTemplate()\n\t{\n\t\tbase.OnApplyTemplate();\n\n\t\t\/\/Find all of the open popups.  Normally there are 2, one for this ContentDialog and one for the background Rectangle\n\t\tvar OpenPopups = VisualTreeHelper.GetOpenPopups(Window.Current);\n\t\tforeach (var OpenPopup in OpenPopups)\n\t\t{\n\t\t\tif (OpenPopup.Child is Rectangle)\n\t\t\t{\n\t\t\t\tScreenBackgroundRectangle = OpenPopup.Child as Rectangle;\n\t\t\t\tScreenBackgroundRectangle.Tapped += OnLockRectangleTapped;\n\t\t\t}\n\t\t}\n\t}\n\n\tprivate void OnLockRectangleTapped(object sender, TappedRoutedEventArgs e)\n\t{\n\t\tthis.Hide();\t\t\/\/Close us \/ the ContentDialog\n\t\tScreenBackgroundRectangle.Tapped -= OnLockRectangleTapped;\n\t}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>Menu &gt; Project &gt; Add new item &gt; Visual C# &gt; Content Dialog You need to set min and max as well as the required Width and Height: 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 [&hellip;]<\/p>\n","protected":false},"author":5,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[100],"tags":[],"class_list":["post-769","post","type-post","status-publish","format-standard","hentry","category-content-dialog-boxes"],"_links":{"self":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/769","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/users\/5"}],"replies":[{"embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/comments?post=769"}],"version-history":[{"count":0,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/posts\/769\/revisions"}],"wp:attachment":[{"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/media?parent=769"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/categories?post=769"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ibex.tech\/csharp\/wp-json\/wp\/v2\/tags?post=769"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}