如何在 WPF 中管理两个单独的显示?
How do I manage two separate displays in WPF?
我正在编写一个应用程序,允许用户 select 在触摸屏显示器上显示一系列地图,然后这些地图也会显示在更大的壁挂式屏幕上。用户将能够 pan/zoom/rotate 浏览地图,我希望壁挂式屏幕能够与触摸屏同步显示这些变化。
管理两个显示器的好方法是什么?
目前,我已将应用程序设置为 MVVM 格式并正在使用 Caliburn.Micro。
每个地图都在自己的 UserControl 中,它们在我的 ShellView 上的 ContentControl 中使用 ShellViewModel 中的 Conductor 和 ActivateItem 激活。我想让活动项目也显示在单独的 Window 中(在壁挂式屏幕上)。
目前的代码如下:
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 上加载地图。我真的只需要在另一个 window 壁挂式显示器
中显示相同的内容
感谢任何帮助,谢谢!
假设您的显示器都连接到同一台设备,您可以使用 Forms.Screen
获取每个显示器的边界。然后将 windows 设置为相同的边界,添加一个 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();
}
}
我正在编写一个应用程序,允许用户 select 在触摸屏显示器上显示一系列地图,然后这些地图也会显示在更大的壁挂式屏幕上。用户将能够 pan/zoom/rotate 浏览地图,我希望壁挂式屏幕能够与触摸屏同步显示这些变化。
管理两个显示器的好方法是什么?
目前,我已将应用程序设置为 MVVM 格式并正在使用 Caliburn.Micro。
每个地图都在自己的 UserControl 中,它们在我的 ShellView 上的 ContentControl 中使用 ShellViewModel 中的 Conductor 和 ActivateItem 激活。我想让活动项目也显示在单独的 Window 中(在壁挂式屏幕上)。
目前的代码如下:
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 上加载地图。我真的只需要在另一个 window 壁挂式显示器
中显示相同的内容感谢任何帮助,谢谢!
假设您的显示器都连接到同一台设备,您可以使用 Forms.Screen
获取每个显示器的边界。然后将 windows 设置为相同的边界,添加一个 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();
}
}