我正在为UWP项目创建多区域演示者。所以我使用Split View创建了汉堡菜单的AppShell文件。有AppShellFrame所以每个页面都显示在这个框架中。但我想显示右侧面板进行设置,所以我添加了第二个分割视图并设置PanePlacement="Right"
以显示右侧,并添加了另一个称为PasscodeFrame的帧。
在第二个分割视图中,我设计了设置视图布局并添加了设置密码的切换按钮。当切换按钮切换时,我想在PasscodeFrame的右侧面板中显示PasscodeView.xaml。我在以下链接中阅读了有关多区域的所有内容:
http://depblog.weblogs.us/2015/11/23/mvvmcross-uwp-splitview/
我按照所有步骤操作,但在AppShellFrame中打开的密码视图不在PasscodeFrame中。我在后面的代码中添加了以下PasscodeView的类定义:
[MvxRegion(" PasscodeFrame&#34)]
我已经声明了这样的app框架:
public Frame AppFrame => AppShellFrame;
所以我认为每个页面都在AppShellFrame中打开。所以我的问题是如何在PasscodeFrame中打开密码视图?我已经使用过MvxRegion,但它不适用于我。以及如何为右侧面板维护后挡?
这是我的代码:
AppShell.xaml
<base:BaseView
<!-- Top-level navigation menu + app content -->
<SplitView x:Name="RootSplitView" DisplayMode="CompactInline" OpenPaneLength="280" IsTabStop="False">
<SplitView.Pane>
<Grid Background="{ThemeResource Background100OffWhiteBrush}">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
</Grid.RowDefinitions>
<!-- A custom ListView to display the items in the pane. The automation Name is set in the ContainerContentChanging event. -->
<!-- MAIN MENU ITEMS -->
<controls:NavMenuListView x:Name="FeedsList"
<!-- ACTION MENU ITEMS -->
<controls:NavMenuListView.Footer>
</controls:NavMenuListView.Footer>
</controls:NavMenuListView>
</Grid>
</SplitView.Pane>
<SplitView.Content>
<!-- OnNavigatingToPage we synchronize the selected item in the nav menu with the current page.
OnNavigatedToPage we move keyboard focus to the first item on the page after it's loaded. -->
<Frame x:Name="AppShellFrame"
Margin="0"
Navigating="OnNavigatingToPage" Navigated="OnNavigatedToPage"
Background="White">
<Frame.ContentTransitions>
<TransitionCollection>
<NavigationThemeTransition>
<NavigationThemeTransition.DefaultNavigationTransitionInfo>
<EntranceNavigationTransitionInfo />
</NavigationThemeTransition.DefaultNavigationTransitionInfo>
</NavigationThemeTransition>
</TransitionCollection>
</Frame.ContentTransitions>
</Frame>
</SplitView.Content>
</SplitView>
<!-- HAMBURGER MENU - Declared last to have it rendered above everything else, but it needs to be the first item in the tab sequence. -->
<ToggleButton x:Name="TogglePaneButton"
Margin="0"
TabIndex="1"
Checked="{x:Bind CheckTogglePaneButtonSizeChanged}"
Unchecked="{x:Bind CheckTogglePaneButtonSizeChanged}"
IsChecked="{Binding IsPaneOpen, ElementName=RootSplitView, Mode=TwoWay}"
AutomationProperties.Name="Menu" ToolTipService.ToolTip="Menu"
Style="{StaticResource SplitViewTogglePaneButtonStyle}"/>
<!-- Right Side Panel -->
<SplitView PanePlacement="Right" x:Name="uiRightSideSplitView">
<SplitView.Pane>
<!--Setting View-->
<ToggleSwitch Toggled="PasscodeToggleSwitch_Toggled" HorizontalAlignment="Stretch" Width="400" Header="passcode enabled"/>
</SplitView.Pane>
<SplitView.Content>
<Frame x:Name="PasscodeFrame" >
</Frame>
</SplitView.Content>
</SplitView>
</Grid>
AppShell.xaml.cs
public sealed partial class AppShell : BaseView
{
public AppShell()
{
this.InitializeComponent();
this.Loaded += AppShell_Loaded;
// AppFrame = AppShellFrame;
}
private void AppShell_Loaded(object sender, RoutedEventArgs e)
{
this.SettingViewModel = new SettingsViewModel();
this.DataContext = this;
}
public Frame AppFrame => AppShellFrame;
private void PasscodeToggleSwitch_Toggled(object sender, RoutedEventArgs e)
{
// Here Setting view model call passcode view model and it open in AppShellFrame. But I want to open in PasscodeFrame.
SettingViewModel.PasscodeEnabled = true;
}
}
PasscodeView.xaml.cs
[MvxRegion(&#34; PasscodeFrame&#34)]
public sealed partial class PasscodeView:BaseView
{
#region Constructor
public PasscodeView()
{
InitializeComponent();
this.Loaded += onLoaded;
// Set navigation cache mode disabled, So each time create new instance of view and view model
NavigationCacheMode = NavigationCacheMode.Disabled;
}
}