Skip to content

SystemParameters.WorkArea is broken on PerMonitorV2 environment. #10459

Open
@incheon-kim

Description

@incheon-kim

Description

When display setting is changed or display scale(dpi) is changed while the application is running, SystemParameters.WorkArea does not return proper value.

If you programatically change Top or Left property of Window that are relative to WorkArea.Width/WorkArea.Height, position of the Window would be absurd.
Width and Height are scaled without any problem. they will be just bigger and smaller to display ratio.

Reproduction Steps

  1. Build app with PerMonitorV2 enabled.
  2. Run app with 100% or 150% display scale ratio.
  3. Change display scale ratio 100% to 150% or 150% to 100%.
  4. Change Window's Top or Left property programatically that are relative to WorkArea's value. (i.e. right bottom corner or work area)
  5. voilà!

Expected behavior

SystemParameters.WorkArea returns proper value.

Actual behavior

awkwardly scaled RECT is returned.

Regression?

I only tested on .net framework environment that supports PerMonitorV2.

Known Workarounds

  1. Use same API that SystemParameters.WorkArea uses. SystemParametersInfo
  2. SystemParameters(SPI_GETWORKAREA, 0, ref RECT, 0)
  3. Get current display scale with VisualTreeHelper.GetDpi() or DpiChanged event.
  4. adjust value of returned RECT from SystemParameters() with DpiScale instance.
  5. RECT.Left/RECT.Right will be divided with DpiScale.DpiScaleX and RECT.Top/RECT.Bottom will be divided with DpiScale.DpiScaleY
  6. divided values are correct WorkArea information.

Impact

No response

Configuration

  • .NET framework (4.7.2, 4.8.1)
  • Windows 10/11 (x64)
  • AnyCPU builds

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions