Secondary monitor error: issue in WPF or graphics driver?

I encountered a strange error in my WPF application and am trying to determine if it is a problem with WPF or my graphics driver so I can report it to the appropriate company. I have a Quadro FX 1700 with the latest drivers (197.54) on a Windows XP system running .NET 3.5 SP1 application.

I have two monitors, my primary on the left and my secondary on the right. The problem occurs when I maximize and then restore the child window of the main window to my main monitor. The child window is the correct size on the primary monitor, but it is drawn on my secondary monitor as if it were still maximized. Moving a child window on the primary monitor moves it on the secondary.

Restored child window is drawn on secondary monitor as if it were still maximized

I made a sample application (code below) that causes this behavior.

  1. Run the application and make sure the main window is on your main monitor.
  2. Double click the main window. A green child window should appear.
  3. Click on the green child window to expand it.
  4. Click on the green child window to restore.

Can anyone else reproduce this issue? On my system, the green child is restored, but then it shows up on my primary and secondary monitors, not just the primary monitor.

App.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" />

      

App.xaml.cs

using System.Windows;
namespace DualMonitorBug { public partial class App : Application { } }

      

Shell.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();
        }
    }
}

      

DialogWindow.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;
           }
        }
    }
}

      

+2


a source to share


3 answers


Okay, I tried something today and it seems like the problem is occurring because the maximizing activity expands the width to the second monitor before moving the window to the top left corner. Therefore, when you normalize the window, the expanded portion is still on the second monitor and will not be cleared until you drag the window to the second monitor.

To work around this issue, before setting WindowState to Maximized, first set the width and height to zeros. This will fix the problem. You might want to cache the current top and left so that when the window is normalized, it will return to its previous position:

Maximum code:



 _oldTop = Top;
_oldHeight = Height;
 Top = Height = 0;
 WindowState = WindowState.Maximized;

      

Normalized code:

Top = _oldTop;
Height = _oldHeight;
WindowState = WindowState.Normal;

      

0


a source


Your application works fine on my system. I am running dual monitors, 3.5SP1, but I have a Radeon HD4670.



+1


a source


I have a problem too. I don't think this is an issue with graphics cards because I tried it on my desktop and then on my extended monitor laptop and always watched for an additional enlarged window on the second monitor after the real window normalized. When it comes to graphics, I would say this is because WPF was not designed to be compatible with all graphics cards.

This only happens when I use custom maximize / minimize buttons and set WindowState based on button click events. If I enlarge the window using the Windows default buttons everything is fine. I was frustrated to find a solution to this problem, so I wrote the code to maximize / normalize by resizing the window.

0


a source







All Articles