我正在编写一个应用程序,允许用户从触摸屏显示器上的一系列地图中进行选择,然后地图也将显示在更大的壁挂式屏幕上。用户可以在地图上平移/缩放/旋转,我希望壁挂式屏幕能够与触摸屏同步显示这些变化。
管理两个显示器的好方法是什么?
目前,我使用MVVM格式设置应用程序,并使用Caliburn.Micro。
每个映射都在自己的UserControl中,它们在ShellView上的ContentControl中使用ShellViewModel中的Conductor和ActivateItem激活。我想让活动项目也显示在一个单独的窗口中(在壁挂式屏幕上)。
这是迄今为止的代码:
ShellView.xaml:
<Grid>
<!--The Content control shows which MapView is currently active-->
<ContentControl x:Name="ActiveItem"/>
<StackPanel>
<TextBlock Text="Select a map.">
<ComboBox>
<Button x:Name="LoadMap1">Map1</Button>
<Button x:Name="LoadMap2">Map2</Button>
<Button x:Name="LoadMap3">Map3</Button>
</ComboBox>
</StackPanel>
</Grid>
ShellViewModel.cs:
public class ShellViewModel : Conductor<object>
{
public ShellViewModel()
{
}
public void LoadMap1()
{
ActivateItem(new MapOneViewModel());
}
public void LoadMap2()
{
ActivateItem(new MapTwoViewModel());
}
public void LoadMap3()
{
ActivateItem(new MapThreeViewModel());
}
}
我不知道这是否是设置它的最佳方法,但它适用于在ShellView上加载地图。我真的只需要在另一个窗口中为壁挂式显示器显示相同的内容
任何帮助表示感谢,谢谢!
假设您的监视器都连接到同一设备,您可以使用Forms.Screen
来获取每个监视器的边界。然后将窗口设置为相同的边界,添加一个Loaded
事件处理程序以最大化它们并调用Show()
:
public partial class App : Application
{
protected override void OnStartup(StartupEventArgs e)
{
base.OnStartup(e);
var primaryScreen = System.Windows.Forms.Screen.PrimaryScreen;
this.MainWindow = new Window();
this.MainWindow.Content = new TextBlock { Text = "This is the primary display." };
this.MainWindow.Left = primaryScreen.Bounds.Left;
this.MainWindow.Top = primaryScreen.Bounds.Top;
this.MainWindow.Width = primaryScreen.Bounds.Width;
this.MainWindow.Height = primaryScreen.Bounds.Height;
this.MainWindow.WindowState = WindowState.Normal;
this.MainWindow.Loaded += (_s, _e) => this.MainWindow.WindowState = WindowState.Maximized;
this.MainWindow.Show();
var secondaryScreen = System.Windows.Forms.Screen.AllScreens.First(screen => screen != primaryScreen);
var secondaryWindow = new Window();
secondaryWindow.Content = new TextBlock { Text = "This is the secondary display." };
secondaryWindow.Left = secondaryScreen.Bounds.Left;
secondaryWindow.Top = secondaryScreen.Bounds.Top;
secondaryWindow.Width = secondaryScreen.Bounds.Width;
secondaryWindow.Height = secondaryScreen.Bounds.Height;
secondaryWindow.WindowState = WindowState.Normal;
secondaryWindow.Loaded += (_s, _e) => secondaryWindow.WindowState = WindowState.Maximized;
secondaryWindow.Show();
}
}