Skip to content

Commit

Permalink
Merge pull request #3000 from PrismLibrary/dev/ds/navview-adapter
Browse files Browse the repository at this point in the history
  • Loading branch information
dansiegel authored Nov 13, 2023
2 parents c5bfab8 + 14a2af0 commit fdc0bbd
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 2 deletions.
12 changes: 10 additions & 2 deletions e2e/Uno/HelloWorld/Views/Shell.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
</DataTemplate>
</toolkit:ExtendedSplashScreen.LoadingContentTemplate>
<Grid>
<Grid.RowDefinitions>
<!--<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*" />
</Grid.RowDefinitions>
Expand All @@ -48,7 +48,15 @@
<Button Command="{Binding NavigateCommand}" CommandParameter="ViewB">Navigate to View B</Button>
</StackPanel>
</StackPanel>
<ContentControl Grid.Row="1" pr:RegionManager.RegionName="ContentRegion" />
<ContentControl Grid.Row="1" pr:RegionManager.RegionName="ContentRegion" />-->
<NavigationView pr:RegionManager.RegionName="ContentRegion"
IsSettingsVisible="false">
<NavigationView.MenuItems>
<NavigationViewItem Content="View A" Tag="ViewA" />
<NavigationViewItem Content="View B" Tag="ViewB" />
</NavigationView.MenuItems>
</NavigationView>

</Grid>
</toolkit:ExtendedSplashScreen>

Expand Down
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();
}
}
3 changes: 3 additions & 0 deletions src/Wpf/Prism.Wpf/PrismInitializationExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ internal static void RegisterDefaultRegionAdapterMappings(this RegionAdapterMapp
regionAdapterMappings.RegisterMapping<Selector, SelectorRegionAdapter>();
regionAdapterMappings.RegisterMapping<ItemsControl, ItemsControlRegionAdapter>();
regionAdapterMappings.RegisterMapping<ContentControl, ContentControlRegionAdapter>();
#if HAS_WINUI
regionAdapterMappings.RegisterMapping<NavigationView, NavigationViewRegionAdapter>();
#endif
}

internal static void RunModuleManager(IContainerProvider containerProvider)
Expand Down

0 comments on commit fdc0bbd

Please sign in to comment.