Prevent duplicate region views and add DefaultView to WPF, Uno, and Avalonia#3402
Draft
dansiegel wants to merge 2 commits into
Draft
Prevent duplicate region views and add DefaultView to WPF, Uno, and Avalonia#3402dansiegel wants to merge 2 commits into
dansiegel wants to merge 2 commits into
Conversation
…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>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Guards against duplicate views in a region when
RegisterViewWithRegionis called multiple times, and addsDefaultViewattached 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)
DefaultViewdoes not add logic toAutoPopulateRegionBehavior. Instead, setting the attached property callsIRegionViewRegistry.RegisterViewWithRegionfrom 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.DefaultViewattached property on WPF / Avalonia / Uno (shared source)OnDefaultViewChangedregisters with the region name from the host'sRegionNameOnSetRegionNameCallbackalso registersDefaultViewwhenRegionNameis set afterDefaultView(XAML property order)Example
Setting
DefaultViewis equivalent to callingRegisterViewWithRegionfor that region; duplicate registrations are ignored by the registry.Tests
RegionManagerFixture— property triggers registration; duplicateDefaultView+ auto-populate yields single viewRegionManagerDefaultViewFixtureRegisterViewWithRegionintegration test only (MAUIAutoPopulateRegionBehaviorunchanged)