Skip to content

Prevent duplicate region views and add DefaultView to WPF, Uno, and Avalonia#3402

Draft
dansiegel wants to merge 2 commits into
masterfrom
cursor/region-default-view-dedup-86e1
Draft

Prevent duplicate region views and add DefaultView to WPF, Uno, and Avalonia#3402
dansiegel wants to merge 2 commits into
masterfrom
cursor/region-default-view-dedup-86e1

Conversation

@dansiegel
Copy link
Copy Markdown
Member

@dansiegel dansiegel commented May 20, 2026

Description

Guards against duplicate views in a region when RegisterViewWithRegion is called multiple times, and adds DefaultView attached property support to WPF, Uno Platform, and Avalonia.

Duplicate registration handling

  • RegionViewRegistry (WPF and MAUI) ignores duplicate registrations for the same view type, target name, or delegate reference.

DefaultView (desktop — not MAUI-style behavior)

DefaultView does not add logic to AutoPopulateRegionBehavior. Instead, setting the attached property calls IRegionViewRegistry.RegisterViewWithRegion from the property changed callback (same path as app code). Existing auto-populate behavior then picks up the registered view when the region is created.

  • RegionManager.DefaultView attached property on WPF / Avalonia / Uno (shared source)
  • OnDefaultViewChanged registers with the region name from the host's RegionName
  • OnSetRegionNameCallback also registers DefaultView when RegionName is set after DefaultView (XAML property order)

Example

<ContentControl prism:RegionManager.RegionName="ContentRegion"
                prism:RegionManager.DefaultView="RegionViewA" />

Setting DefaultView is equivalent to calling RegisterViewWithRegion for that region; duplicate registrations are ignored by the registry.

Tests

Platform Coverage
WPF / Avalonia RegionManagerFixture — property triggers registration; duplicate DefaultView + auto-populate yields single view
Uno RegionManagerDefaultViewFixture
MAUI Duplicate RegisterViewWithRegion integration test only (MAUI AutoPopulateRegionBehavior unchanged)
Open in Web Open in Cursor 

cursoragent and others added 2 commits May 20, 2026 20:33
…ktop platforms

RegisterViewWithRegion now ignores duplicate registrations for the same view
type, target name, or delegate so a region receives only one instance when
code runs more than once during the app lifecycle.

Add RegionManager.DefaultView attached property to WPF, Avalonia, and Uno
(shared WPF source) with AutoPopulateRegionBehavior support matching MAUI.
DefaultView population skips views already present from registry registration.

Add unit tests for WPF, Avalonia, Uno, and MAUI covering duplicate
RegisterViewWithRegion and DefaultView scenarios.

Co-authored-by: Dan Siegel <dsiegel@avantipoint.com>
…havior

Revert AutoPopulateRegionBehavior to its original implementation without
IHostAwareRegionBehavior or DefaultView population logic.

When DefaultView is set on a region host, RegionManager now calls
IRegionViewRegistry.RegisterViewWithRegion from the attached property
changed callback. RegionName assignment also registers DefaultView when
it was set first, covering arbitrary XAML property order.

Restore MAUI AutoPopulateRegionBehavior to its prior implementation.
Update tests to verify registration through RegionManager rather than
the auto-populate behavior.

Co-authored-by: Dan Siegel <dsiegel@avantipoint.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants