{"id":508,"date":"2014-06-18T10:11:28","date_gmt":"2014-06-18T10:11:28","guid":{"rendered":"http:\/\/www.nikola-breznjak.com\/blog\/?p=508"},"modified":"2015-08-20T11:28:14","modified_gmt":"2015-08-20T11:28:14","slug":"maximizing-a-wpf-window-to-second-monitor","status":"publish","type":"post","link":"https:\/\/nikola-breznjak.com\/blog\/quick-tips\/maximizing-a-wpf-window-to-second-monitor\/","title":{"rendered":"Maximizing WPF Window to second monitor"},"content":{"rendered":"<p>So, if you have this in the code behind:<\/p>\n<pre class=\"lang:default decode:true\">if (System.Windows.Forms.Screen.AllScreens.Length &gt;= Config.ScreenNumber)\r\n{\r\n    System.Drawing.Rectangle screenBounds = System.Windows.Forms.Screen.AllScreens[Config.ScreenNumber - 1].Bounds;\r\n    this.Left = screenBounds.Left;\r\n    this.Top = screenBounds.Top;\r\n}<\/pre>\n<p>And this in your XAML\u00a0file on Window:<\/p>\n<pre class=\"lang:default decode:true\">&lt;Window WindowState=\"Maximized\" ...<\/pre>\n<p>Asuming that Config.ScreenNumber equals 2, it will not position itself on the second screen no matter what you do, it will maximize on your main screen. What helped in the end was to remove the WindowState from the XAML\u00a0definition and to add Loaded event handler:<\/p>\n<pre class=\"lang:default decode:true\">private void Window_Loaded(object sender, RoutedEventArgs e)\r\n{\r\n    this.WindowState = WindowState.Maximized;\r\n}<\/pre>\n","protected":false},"excerpt":{"rendered":"<p>So, if you have this in the code behind: if (System.Windows.Forms.Screen.AllScreens.Length &gt;= Config.ScreenNumber) { System.Drawing.Rectangle screenBounds = System.Windows.Forms.Screen.AllScreens[Config.ScreenNumber &#8211; 1].Bounds; this.Left = screenBounds.Left; this.Top = screenBounds.Top; } And&hellip;<\/p>\n","protected":false},"author":1,"featured_media":509,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[15,33],"tags":[],"class_list":["post-508","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-quick-tips","category-wpf"],"_links":{"self":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/508","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/comments?post=508"}],"version-history":[{"count":3,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/508\/revisions"}],"predecessor-version":[{"id":2118,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/posts\/508\/revisions\/2118"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media\/509"}],"wp:attachment":[{"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/media?parent=508"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/categories?post=508"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nikola-breznjak.com\/blog\/wp-json\/wp\/v2\/tags?post=508"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}