-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3000 from PrismLibrary/dev/ds/navview-adapter
- Loading branch information
Showing
3 changed files
with
50 additions
and
2 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
37 changes: 37 additions & 0 deletions
37
src/Uno/Prism.Uno/Navigation/Regions/NavigationViewRegionAdapter.cs
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,37 @@ | ||
using Microsoft.UI.Xaml; | ||
using Microsoft.UI.Xaml.Controls; | ||
|
||
namespace Prism.Navigation.Regions; | ||
|
||
public sealed class NavigationViewRegionAdapter : RegionAdapterBase<NavigationView> | ||
{ | ||
public NavigationViewRegionAdapter(IRegionBehaviorFactory regionBehaviorFactory) | ||
: base(regionBehaviorFactory) | ||
{ | ||
} | ||
|
||
protected override void Adapt(IRegion region, NavigationView regionTarget) | ||
{ | ||
regionTarget.BackRequested += delegate | ||
{ | ||
if (region.NavigationService.Journal.CanGoBack) | ||
region.NavigationService.Journal.GoBack(); | ||
}; | ||
|
||
regionTarget.SelectionChanged += delegate | ||
{ | ||
if (regionTarget.SelectedItem is FrameworkElement item && item.Tag is string navigationTarget && !string.IsNullOrEmpty(navigationTarget)) | ||
region.RequestNavigate(navigationTarget); | ||
}; | ||
|
||
region.ActiveViews.CollectionChanged += delegate | ||
{ | ||
regionTarget.Content = region.ActiveViews.FirstOrDefault(); | ||
}; | ||
} | ||
|
||
protected override IRegion CreateRegion() | ||
{ | ||
return new SingleActiveRegion(); | ||
} | ||
} |
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