wpf双显示器应用程序?
我对 WPF 很陌生。我想创建一个双显示器/投影仪应用程序。我想要做的是在一台显示器上显示“演示者屏幕”,在辅助显示器上显示另一个面板,类似于 powerpoint 的工作原理。我正在努力将注意力集中在面板和 XAML 上。所以我想要的是用户单击 screen1 上的按钮,并且 screen2 上的信息会更新。
我正在使用这段代码:
this.Width = System.Windows.SystemParameters.VirtualScreenWidth;
this.Height = System.Windows.SystemParameters.VirtualScreenHeight;
this.Top = 0;
this.Left = 0;
设置屏幕的宽度和高度。
编辑:
后面的目标是使 screen2 根据 screen1 上的选择从数据库中检索项目
问题:教程、要去的地方、如何通过监视器 1 上的按钮更新监视器 2 的提示
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
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
简答
创建一个在两个视图之间共享的视图模型;将其中一个视图设为主(进行更改),将另一个视图设为纯演示。景色是新的窗户。最初不要关心窗口位置(我们稍后会讨论),只需让共享视图模型正常工作即可。
提示:研究 MVVM 模式。 Google 有很多关于该主题的文章。
长答案
在研究了 MVVM 并创建了一些示例应用程序(通过 scatch 或使用框架)后,下面是您想要实现的一些附加功能,以创建“类似 powerpoint”的应用程序。
全屏模式
至少您会希望演示窗口是全屏的。要实现此目的,请将
WindowStyle
设置为None
,并将AllowsTransparency
设置为True
。如果您想让第二个窗口也全屏显示,您可能需要执行一些 Win32 覆盖,以使窗口在不覆盖任务栏的情况下正确最大化(如果您想知道如何执行此操作,请发表评论)。
检测多个监视器
使用
Win32
Interop 命令获取监视器的大小和位置。互联网上有很多文章可以帮助您解决此问题(或发布另一个 StackoverFlow 问题)。这将是一个简洁的™功能,因为它将正确定位两个窗口(使用辅助屏幕作为演示文稿)。
这就是我现在能想到的全部内容,如果您对 MVVM 或上述任何其他问题有任何疑问,请回帖。
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
toNone
andAllowsTransparency
toTrue
.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.
1)你应该有2个窗口,看起来我会让monitor2成为monitor1的子窗口(毕竟,它是一个子窗口;)
我的意思是,App.xaml中的StartupUri应该指向monitor1,并且在monitor1的构造函数中,您应该创建一个monitor2的实例(如果我这样做的话,这将是一个单例)。
2) 最大化第二个屏幕上的窗口:
订阅窗口的 Loaded 事件(在代码隐藏中),并设置
更多信息(和源): 这里
3) 至于如何让monitor2在monitor1中设置某些东西时做出反应,让monitor1和monitor2绑定到同一个ViewModel,只是他们表现出不同的东西。
希望这有帮助!
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
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!