Skip to content

Commit

Permalink
added possibility to get IRegion by region name
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex-Dobrynin committed Oct 18, 2024
1 parent d818e66 commit 2adb957
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion MPowerKit.Regions/MPowerKit.Regions.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

<GeneratePackageOnBuild>True</GeneratePackageOnBuild>
<Title>MPowerKit.Regions</Title>
<Version>1.3.0</Version>
<Version>1.3.1</Version>
<Authors>MPowerKit,Alex Dobrynin</Authors>
<Description>.NET MAUI MVVM navigation framework. It supports regular/modal navigation, opening/closing windows, regions</Description>
<Copyright>MPowerKit</Copyright>
Expand Down
13 changes: 13 additions & 0 deletions MPowerKit.Regions/RegionManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,19 @@ public virtual async ValueTask<NavigationResult> NavigateTo(string regionName, s
}
}

public virtual IRegion? GetRegionByName(string regionName)
{
if (!_regionHolders.TryGetValue(regionName, out WeakReference<ContentView>? value))
{
throw new ArgumentNullException($"There is not registered region with name {regionName}");
}

var regionHolder = (value.TryGetTarget(out var target) ? target : null)
?? throw new NullReferenceException("Region was disposed");

return ViewServiceProviderAttached.GetServiceScope(regionHolder)?.ServiceProvider.GetRequiredService<IRegion>();
}

public virtual IEnumerable<IRegion> GetRegions(VisualElement? regionHolder)
{
var holders = RegionHolders.Where(v => MvvmHelpers.IsParentRegionHolder(v, regionHolder));
Expand Down

0 comments on commit 2adb957

Please sign in to comment.