Skip to content

PlatformModeDetector.InDesignMode() not working in WPF designer for nested UserControls #819

@wldevries

Description

@wldevries

Describe the bug
PlatformModeDetector.InDesignMode() returns incorrect information when used in controls that are used within a control you are working on in the WPF designer.

Steps To Reproduce
Provide the steps to reproduce the behavior:

  1. Create UserControlA with an OnLoaded event handler guarded by PlatformModeDetector.InDesignMode() throwing an exception when left through
  2. Create UserControlB that has UserControlA hosted somewhere within it
  3. Observe the WPF designer with Control display option: Show all controls

Expected behavior
Designer works

Screenshots
Designer shows an error with a stacktrace leading up to the exception created in step 1 in the OnLoaded event handler.

Environment

  • OS: Windows 10
  • Version: 21H1
  • Device: x64
  • Splat: 13.1.42

Additional context
The built in WPF method DesignerProperties.GetIsInDesignMode(this) just works, when that is used instead in the event handler of UserControlA things that should not be run in design mode are skipped.

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions