Skip to content

Commit b171f51

Browse files
committed
chore: adding global region navigation
1 parent fda8773 commit b171f51

File tree

3 files changed

+101
-0
lines changed

3 files changed

+101
-0
lines changed

docs/navigation/regions/index.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,4 @@ Prism provides guidance on implementing both styles of navigation, focusing on t
3535
| [Navigation Journal](xref:Navigation.Regions.NavigationJournal) | Use the navigation journal to allow the user to navigate from within the view. |
3636
| [Passing Parameters](xref:Navigation.Regions.PassingParameters) | Pass data to the view being navigated to. |
3737
| [View and View Model Participation](xref:Navigation.Regions.ViewViewModelParticipation) | Link your views and view models to the navigation system. |
38+
| [Global Region Observer](xref:Plugins.ObservableRegions) | Observe and react to Navigation Events globally. |

docs/plugins/regions.md

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
uid: Plugins.ObservableRegions
3+
---
4+
5+
# Getting Started
6+
7+
While it has always been possible to respond to Region Navigation Events such as Navigating, Navigated and NavigationFailed through the IRegionNavigationService, this hasn't been something that is particularly easy to deal with from a global scope. This is in part due to the fact that each Region has it's own Navigation Service. `Prism.Plugin.ObservableRegions` is a new cross platform package from the Prism team exclusively available to Commercial Plus subscribers. For the first time you now have the ability to manage Region Navigation Events from a global context.
8+
9+
## [.NET MAUI](#tab/maui)
10+
11+
```cs
12+
public static class PrismStartup
13+
{
14+
public static void Configure(PrismAppBuilder builder) =>
15+
builder.RegisterTypes(RegisterTypes)
16+
.OnInitialized(container => container.ObserveRegionNavigation(RegionNavigationObserver));
17+
18+
private static void RegisterTypes(IContainerRegistry containerRegistry)
19+
{
20+
containerRegistry.AddObservableRegions();
21+
}
22+
23+
private static void RegionNavigationObserver(IContainerProvider container, IGlobalRegionNavigationObserver observer) =>
24+
observer.Navigation
25+
.Where(x => x.Event == RegionNavigationEventType.Failed)
26+
.Subscribe(regionEvent => {
27+
var logger = container.Resolve<ILogger>();
28+
logger.Report(regionEvent.Error!);
29+
});
30+
}
31+
```
32+
33+
## [WPF](#tab/wpf)
34+
35+
```cs
36+
public partial class App : Application
37+
{
38+
protected override void RegisterTypes(IContainerRegistry containerRegistry)
39+
{
40+
containerRegistry.AddObservableRegions();
41+
}
42+
43+
protected override void OnInitialized()
44+
{
45+
Container.ObserveRegionNavigation(RegionNavigationObserver);
46+
}
47+
48+
private static void RegionNavigationObserver(IContainerProvider container, IGlobalRegionNavigationObserver observer) =>
49+
observer.Navigation
50+
.Where(x => x.Event == RegionNavigationEventType.Failed)
51+
.Subscribe(regionEvent => {
52+
var logger = container.Resolve<ILogger>();
53+
logger.Report(regionEvent.Error!);
54+
});
55+
}
56+
```
57+
58+
## [Uno Platform](#tab/uno-platform)
59+
60+
```cs
61+
public partial class App : Application
62+
{
63+
protected override void RegisterTypes(IContainerRegistry containerRegistry)
64+
{
65+
containerRegistry.AddObservableRegions();
66+
}
67+
68+
protected override void OnInitialized()
69+
{
70+
Container.ObserveRegionNavigation(RegionNavigationObserver);
71+
}
72+
73+
private static void RegionNavigationObserver(IContainerProvider container, IGlobalRegionNavigationObserver observer) =>
74+
observer.Navigation
75+
.Where(x => x.Event == RegionNavigationEventType.Failed)
76+
.Subscribe(regionEvent => {
77+
var logger = container.Resolve<ILogger>();
78+
logger.Report(regionEvent.Error!);
79+
});
80+
}
81+
```
82+
83+
---
84+
85+
## RegionNavigationEvent
86+
87+
Note that this event does not inherit from PubSubEvent and is not fired from the `IEventAggregator`. The event will give you the following record with access to the Region that is being navigated, the event type, the NavigationContext, the Uri and the ViewName that was being navigated. When the Event Type is null you will also have an Error. The Error will always be null when Navigating and Navigated are the event types.
88+
89+
```cs
90+
public record RegionNavigationEvent(IRegion Region, RegionNavigationEventType Event, NavigationContext Context, Uri Uri, string Name, Exception? Error = null);
91+
92+
public enum RegionNavigationEventType
93+
{
94+
Navigating,
95+
Navigated,
96+
Failed
97+
}
98+
```

docs/plugins/toc.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,7 @@
22
href: essentials/toc.yml
33
- name: Logging
44
href: logging/toc.yml
5+
- name: Observable Regions
6+
href: regions.md
57
- name: Popups
68
href: popups.md

0 commit comments

Comments
 (0)