dotnet / dotnet/wpf

WPF Window Fails to Redraw Contents in Areas on Win10 with Two Monitors

Open
#1,320 0 comments 0 reactions 0 assignees View on GitHub
.NET Framework Bug
Dominant language
C#
Stars
7.7k
Forks
1.3k
Avg merge
1d 11h
Merged PRs (30d)
61

Description

I am going to post this link here to the original post on stackoverflow:

https://stackoverflow.com/questions/54961745/wpf-window-fails-to-redraw-contents-in-areas-on-win10-with-two-monitors

Now I will duplicate the above post for those that don't want to link through:

Okay, first off here is an image representing the 4K screen and 1080p screen with the dead zone. Second, the 4K screen is set to 125% scaling. Third if the 1080p is also set to 125% the bug still occurs. However, if you set the 4K screen back to 100%, then everything works as expected.

https://i.stack.imgur.com/y11qJ.png

If the Window is moved via the mouse onto the 1080p it works as expected. However, if you use the Top and Left of the window to move it, then it experiences the issue.

Basically, the window moves on the second screen via Top and Left but any type of code that tries to manipulate the graphics in the window is simply ignored in the dead zone. This includes but not limited to BackgroundColor, Image, etc.

I am not sure what is causing this, but it seems when the window is moved via Top and Left, it is not setting the owning display properly when the primary screen is not at 100% scale.


If you want code as an example that causes it then:

public partial class Magnifier : Window

{
public Magnifier()
{
InitializeComponent();
}

public void Update(D.Bitmap bmp, double x, double y)
{
Preview.Source = GetSource(bmp);
Top = y;
Left = x;
}

public static BitmapSource GetSource(System.Drawing.Bitmap source)
{
var rect = new System.Drawing.Rectangle(0, 0, source.Width, source.Height);

var bitmapData = source.LockBits(
rect,
ImageLockMode.ReadWrite,
System.Drawing.Imaging.PixelFormat.Format32bppArgb);

try
{
var size = (rect.Width * rect.Height) * 4;

return BitmapSource.Create(
source.Width,
source.Height,
source.HorizontalResolution,
source.VerticalResolution,
PixelFormats.Bgra32,
null,
bitmapData.Scan0,
size,
bitmapData.Stride);
}
finally
{
source.UnlockBits(bitmapData);
}
}
}

In the above code, the x and y have already been scaled to the proper DPI before they are passed to the Update method. The window does indeed move to the expected location on both screens. Even though I have a bitmap, I have also tested with just trying to set the BackgroundColor as well. It also fails to update in the dead zone.


The window is updated in a DispatchTimer and works as expected everywhere, except the dead zone.

Video Card: Nvidia 1080 GTX - Latest Drivers

I have tested with the following .Net versions: 4.6, 4.7.1, and 4.7.2.

Any thoughts or suggestions on this issue? Has anyone else experienced this issue?

# Edit 1:

My suspicion is indeed correct, the window is not updating its display owner / capabilities to the secondary screen, if positioned with Top and Left. I placed the window on start up in the dead zone. It did not work. I then grabbed it with the mouse, and the window dpi adjusted and set itself to the secondary display. After that it worked with no issues. However, this really isn't a solution for me, as the window is meant to follow the mouse around.

_This issue has been moved from https://developercommunity.visualstudio.com/content/problem/475414/wpf-window-fails-to-redraw-contents-in-areas-on-wi.html
VSTS ticketId: 807159_
_These are the original issue comments:_

Visual Studio Feedback System on 3/3/2019, 06:52 PM (137 days ago):

We have directed your feedback to the appropriate engineering team for further evaluation. The team will review the feedback and notify you about the next steps.

_These are the original issue solutions:_
(no solutions)

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.