我在我的 WPF 应用程序中发现了一个奇怪的错误,我正在尝试确定它是 WPF 还是我的图形驱动程序的问题,以便我可以将其报告给相应的公司。我有一个 Quadro FX 1700,在 Windows XP 系统上运行最新的驱动程序 (197.54),运行 .NET 3.5 SP1 应用程序。
我有双显示器,左侧是主显示器,右侧是辅助显示器。当我最大化然后在我的主监视器上恢复主窗口的子窗口时,就会出现问题。子窗口在主监视器上的大小正确,但它在我的辅助监视器上绘制,就好像它仍然处于最大化状态一样。在主监视器上移动子窗口将其移动到辅助监视器上。
我制作了一个导致这种行为的示例应用程序(代码如下)。
- 启动应用程序并确保主窗口位于您的主监视器上。
- 双击主窗口。应该会出现一个绿色的子窗口。
- 单击绿色子窗口最大化。
- 单击绿色子窗口进行恢复。
其他人可以重现这个问题吗?在我的系统上,绿色孩子恢复了,但随后它被绘制在我的主显示器和辅助显示器上,而不仅仅是主显示器。
应用程序.xaml
<Application
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="DualMonitorBug.App"
StartupUri="Shell.xaml" />
应用程序.xaml.cs
using System.Windows;
namespace DualMonitorBug { public partial class App : Application { } }
壳牌.xaml
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="DualMonitorBug.Shell"
Title="Shell" Height="480" Width="640"
MouseDoubleClick="ShowDialog" />
Shell.xaml.cs
using System.Windows;
using System.Windows.Input;
namespace DualMonitorBug
{
public partial class Shell : Window
{
public Shell()
{
InitializeComponent();
}
private void ShowDialog(object sender, MouseButtonEventArgs e)
{
DialogWindow dialog = new DialogWindow();
dialog.Owner = this;
dialog.Show();
}
}
}
对话框窗口.xaml
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="DualMonitorBug.DialogWindow"
Title="Dialog Window" Height="240" Width="320"
AllowsTransparency="True"
Background="Green"
MouseLeftButtonDown="ShowHideDialog"
WindowStyle="None" />
DialogWindow.xaml.cs
using System.Windows;
using System.Windows.Input;
namespace DualMonitorBug
{
public partial class DialogWindow : Window
{
public DialogWindow() { InitializeComponent(); }
private void ShowHideDialog(object sender, MouseButtonEventArgs e)
{
if (e.ClickCount == 1)
{
if (this.WindowState == WindowState.Normal)
{
this.DragMove();
}
}
else
{
this.WindowState
= (this.WindowState == WindowState.Normal)
? WindowState.Maximized
: WindowState.Normal;
}
}
}
}