Eonasdan
Eonasdan

Reputation: 7765

wpf dual monitor application?

I'm very new to WPF. I want to create a dual monitor/projector application. What I want to do is have the "presenters screen" on one monitor and another panel on the secondary monitor, similar to how powerpoint works. I'm struggling to wrap my mind around the panels and XAML. So what I'm after is user clicks on a button on screen1 and information gets updated on screen2.

I'm using this code:

this.Width = System.Windows.SystemParameters.VirtualScreenWidth;
this.Height = System.Windows.SystemParameters.VirtualScreenHeight;
this.Top = 0;
this.Left = 0;

to set the width and height of the screen.

Edit:

The later goal is to cause screen2 to retrieve items out of a database based on the selection on screen1

Question: tutorials, places to go, nudges on how to update monitor2 from a button on monitor1

Upvotes: 1

Views: 10059

Answers (2)

Dennis
Dennis

Reputation: 20571

Short Answer

Create a view model that shared between two views; make one of the views the master (makes the changes) and the other pure presentation. The views are new windows. Initially do not be concerned with the window position (we'll get to that later) just get the shared viewmodel working.

Tip: research the MVVM pattern. Google has a lot of articles on the subject.

Long Answer

After you have researched MVVM and created a few example applications (from scatch or using a framework), below are few additional features you want implement to create the "powerpoint-like" application.

  • Fullscreen Mode

    At the very least you will want the presentation window to be full screen. To achieve this, you set the WindowStyle to None and AllowsTransparency to True.

    If you want to make the second window also fullscreen you may need to do some Win32 overrides to get the window to maximize properly without covering the taskbar (post a comment if you want to know how to do this).

  • Detect Multiple Monitors

    Get the size and position of the monitors using Win32 Interop commands. There will be plenty of articles on the Internet that will help you with this (or post another StackoverFlow question).

    This would be a neat™ feature as it will position the two windows correctly (use the secondary screen as the presentation).


That is all that I can think of now, post-back if you any questions on MVVM or any of the additional points above.

Upvotes: 5

Louis Kottmann
Louis Kottmann

Reputation: 16648

1) You should have 2 Windows, the way this looks I'd make monitor2 a child window of monitor1 (after all, it is a child ;)
What i mean by that, is that StartupUri in App.xaml should point to monitor1, and in monitor1's constructor, you should create an instance of monitor2 (which would be a singleton if i were to do it).

2) To maximize a window on the second screen: Subscribe to the Loaded event of the window (in code-behind), and set

private void Window_Loaded(object sender, RoutedEventArgs e) {
            WindowState = WindowState.Maximized;
        }

More info (and source): here

3) As to how to make monitor2 react when you set something in monitor1, make monitor1 and monitor2 bind to the same ViewModel, only they show different stuff.

Hope this helps!

Upvotes: 4

Related Questions