-
Notifications
You must be signed in to change notification settings - Fork 112
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: adding global region navigation
- Loading branch information
Showing
3 changed files
with
101 additions
and
0 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,98 @@ | ||
--- | ||
uid: Plugins.ObservableRegions | ||
--- | ||
|
||
# Getting Started | ||
|
||
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. | ||
|
||
## [.NET MAUI](#tab/maui) | ||
|
||
```cs | ||
public static class PrismStartup | ||
{ | ||
public static void Configure(PrismAppBuilder builder) => | ||
builder.RegisterTypes(RegisterTypes) | ||
.OnInitialized(container => container.ObserveRegionNavigation(RegionNavigationObserver)); | ||
|
||
private static void RegisterTypes(IContainerRegistry containerRegistry) | ||
{ | ||
containerRegistry.AddObservableRegions(); | ||
} | ||
|
||
private static void RegionNavigationObserver(IContainerProvider container, IGlobalRegionNavigationObserver observer) => | ||
observer.Navigation | ||
.Where(x => x.Event == RegionNavigationEventType.Failed) | ||
.Subscribe(regionEvent => { | ||
var logger = container.Resolve<ILogger>(); | ||
logger.Report(regionEvent.Error!); | ||
}); | ||
} | ||
``` | ||
|
||
## [WPF](#tab/wpf) | ||
|
||
```cs | ||
public partial class App : Application | ||
{ | ||
protected override void RegisterTypes(IContainerRegistry containerRegistry) | ||
{ | ||
containerRegistry.AddObservableRegions(); | ||
} | ||
|
||
protected override void OnInitialized() | ||
{ | ||
Container.ObserveRegionNavigation(RegionNavigationObserver); | ||
} | ||
|
||
private static void RegionNavigationObserver(IContainerProvider container, IGlobalRegionNavigationObserver observer) => | ||
observer.Navigation | ||
.Where(x => x.Event == RegionNavigationEventType.Failed) | ||
.Subscribe(regionEvent => { | ||
var logger = container.Resolve<ILogger>(); | ||
logger.Report(regionEvent.Error!); | ||
}); | ||
} | ||
``` | ||
|
||
## [Uno Platform](#tab/uno-platform) | ||
|
||
```cs | ||
public partial class App : Application | ||
{ | ||
protected override void RegisterTypes(IContainerRegistry containerRegistry) | ||
{ | ||
containerRegistry.AddObservableRegions(); | ||
} | ||
|
||
protected override void OnInitialized() | ||
{ | ||
Container.ObserveRegionNavigation(RegionNavigationObserver); | ||
} | ||
|
||
private static void RegionNavigationObserver(IContainerProvider container, IGlobalRegionNavigationObserver observer) => | ||
observer.Navigation | ||
.Where(x => x.Event == RegionNavigationEventType.Failed) | ||
.Subscribe(regionEvent => { | ||
var logger = container.Resolve<ILogger>(); | ||
logger.Report(regionEvent.Error!); | ||
}); | ||
} | ||
``` | ||
|
||
--- | ||
|
||
## RegionNavigationEvent | ||
|
||
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. | ||
|
||
```cs | ||
public record RegionNavigationEvent(IRegion Region, RegionNavigationEventType Event, NavigationContext Context, Uri Uri, string Name, Exception? Error = null); | ||
|
||
public enum RegionNavigationEventType | ||
{ | ||
Navigating, | ||
Navigated, | ||
Failed | ||
} | ||
``` |
This file contains 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