WPF Full screen accross multiple monitors
I've been working on a cool instillation project for Microsoft and one of the things I need to do is have my application go full screen across multiple monitors. By default, if you maximize your application window inside Windows it fills the Primary Screen or Active screen but it doesn't go across all monitors. You have to manually drag the application window across to have it show up on more than one monitor. What if you wanted to make a screen saver for multiple monitors? Doing some internet searching I pieced together this little solution. Here is a code snippet that maximizes your WPF app window across all monitors in multi-mon setups. It also adds a listener for the ESC key to close the window down. Hope this helps people find this solution faster in the future.
Then in your XAML make sure you don't have any values set so the code behind can do it's thing.
Then in your XAML make sure you don't have any values set so the code behind can do it's thing.





2 Comments:
Thanks for the code post, I've been wanting to toy with creating a C# WPF screensaver and thus far have only been able to fill one screen.
However, this code has one issue. You're always adding to both width and height while calculating resolution. The problem with that is my dual-monitor side-by-side setup, the height of the first monitor is added to the height of the second, which doesn't make sense since they're side-by-side. It draws to an area twice as high as my actual setup. Do you have any idea how this could be revised so that the actual total resolution is reflected by the values of width and height?
I do indeed... I actually found this problem myself when I moved to a different computer.
I will need to update the code so that the height does not increase. The line should be as follows:
height = screen.WorkingArea.Height;
If you remove the += from the code, then it will use the Screen Height from the right most screen. If all your screens are the same height, then you have no issues.
If you want to make sure you use the LARGEST height, in case of multiple screen heights, you'll have to put some additional logic in there that check the value of the previous screen height and then just make sure the highest is used.
Glad this helped you out and I thank you for responding with the error. I will update the blog post right now!
Cheers, Ryan
Post a Comment
Links to this post:
Create a Link
<< Home