{"id":816,"date":"2012-10-23T23:46:14","date_gmt":"2012-10-23T12:46:14","guid":{"rendered":"http:\/\/ntsblog.homedev.com.au\/?p=816"},"modified":"2013-01-24T00:32:23","modified_gmt":"2013-01-23T13:32:23","slug":"modal-dialog-wpf","status":"publish","type":"post","link":"https:\/\/ntsblog.homedev.com.au\/index.php\/2012\/10\/23\/modal-dialog-wpf\/","title":{"rendered":"How to make a Modal Dialog in WPF"},"content":{"rendered":"<div id=\"ntsbl-2333060549\" class=\"ntsbl-before-content ntsbl-entity-placement\"><script async src=\"\/\/pagead2.googlesyndication.com\/pagead\/js\/adsbygoogle.js?client=ca-pub-6288941070289539\" crossorigin=\"anonymous\"><\/script><ins class=\"adsbygoogle\" style=\"display:inline-block;width:728px;height:90px;\" \ndata-ad-client=\"ca-pub-6288941070289539\" \ndata-ad-slot=\"9356781486\"><\/ins> \n<script> \n(adsbygoogle = window.adsbygoogle || []).push({}); \n<\/script>\n<\/div><h2>The Scenario<\/h2>\n<p>\nI have created a c# WPF application. The app has an &#8220;About&#8221; page that I want to show as a modal dialog.\n<\/p>\n<h2>The Problem<\/h2>\n<p>\nThe issue is when the &#8220;About&#8221; dialog is open and the user  Alt+Tab&#8217;s the &#8220;About&#8221; dialog is visible as a separate tile in the Alt+Tab list. The about dialog also has a url link. Clicking this opens a browser window. When the user Alt+Tab&#8217;s back to the application the about dialog is visible whilst the calling app is now behind the web browser.\n<\/p>\n<h2>Solution<\/h2>\n<p>\nFirstly, in WPF create your dialog as a &#8220;Window&#8221; control.<\/p>\n<p>In windows forms you would do:<\/p>\n<p>[csharp]<br \/>\n  frmAbout about = new frmAbout();<br \/>\n  about.ShowDialog(this);<br \/>\n[\/csharp]<\/p>\n<p>In WPF its the same concept but syntactically slightly different:<\/p>\n<p>[csharp]<br \/>\n  About aboutWindow = new About();<br \/>\n  aboutWindow.Owner = this;<br \/>\n  aboutWindow.ShowDialog();<br \/>\n[\/csharp]<\/p>\n<p>This will open the window as a modal dialog. <\/p>\n<p>One other setting to play with on the About window is <b>WindowsStartUpLocation<\/b><br \/>\nOptions:<\/p>\n<ul>\n<li>CenterScreen\n<li>CenterOwner\n<li>Manual\n<\/ul>\n<p>Setting it as &#8220;CenterOwner&#8221; will open in the centre of the calling Window. I set mine to centre screen as it looked a bit funny starting centre of the owner.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The Scenario I have created a c# WPF application. The app has an &#8220;About&#8221; page that I want to show as a modal dialog. The [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[5,24],"tags":[],"class_list":["post-816","post","type-post","status-publish","format-standard","hentry","category-c","category-wpf"],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"_links":{"self":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/posts\/816","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/comments?post=816"}],"version-history":[{"count":0,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/posts\/816\/revisions"}],"wp:attachment":[{"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/media?parent=816"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/categories?post=816"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ntsblog.homedev.com.au\/index.php\/wp-json\/wp\/v2\/tags?post=816"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}