c# - 我希望除 UWP 中的“LoginPage”之外的所有页面都可以访问“SplitViewRoot”,如何使其工作?
问题描述
我是一个从事 uwp 项目的初学者,我创建了一个类似这样的“SplitViewRootControl”:
<Grid>
<Image Source="ms-appx:///Assets/Background.jpg" Stretch="Fill"/>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<SplitView x:Name="SplitViewRootControl" Grid.Row="1" DisplayMode="CompactInline" OpenPaneLength="150" CompactPaneLength="0" PaneBackground="Black" Opacity=".8">
<SplitView.Pane>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="auto"/>
<RowDefinition Height="auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<RelativePanel>
<Image x:Name="userIcon" Source="ms-appx:///Assets/user.png" Width="35" RelativePanel.AlignLeftWithPanel="True" Margin="10,20,0,0"/>
<TextBlock x:Name="user" RelativePanel.RightOf="userIcon" RelativePanel.AlignVerticalCenterWith="userIcon" RelativePanel.AlignTopWith="userIcon" Text="User:" FontSize="13" Margin="5,18,0,0" Foreground="Ivory" />
<TextBlock x:Name="userName" RelativePanel.RightOf="userIcon" RelativePanel.Below="user" Text="Chen Yinjue" FontSize="13" Margin="5,0,0,0" Foreground="Ivory" />
</RelativePanel>
<GridView Grid.Row="1" HorizontalAlignment="Center" Margin="0,50,0,0" ScrollViewer.VerticalScrollBarVisibility="Auto">
<StackPanel>
<Image Source="ms-appx:///Assets/messenger.png" Width="70" />
<TextBlock Text="Messenger" FontSize="18" Foreground="Ivory" HorizontalAlignment="Center" Margin="0,0,0,50"/>
<Image Source="ms-appx:///Assets/warning.png" Width="70" />
<TextBlock Text="Alert" FontSize="18" Foreground="Ivory" HorizontalAlignment="Center" Margin="0,0,0,50"/>
<Image Source="ms-appx:///Assets/cctv.png" Width="70" />
<TextBlock Text="Camera Setup" FontSize="18" Foreground="Ivory" HorizontalAlignment="Center" Margin="0,0,0,50"/>
<Image Source="ms-appx:///Assets/more.png" Width="70" />
<TextBlock Text="More" FontSize="18" Foreground="Ivory" HorizontalAlignment="Center" />
</StackPanel>
</GridView>
<Button Grid.Row="2"
Style="{StaticResource ResourceKey=appButtonStyle}"
HorizontalAlignment="Center"
Content="Log Out"
FontSize="20"
Foreground="White"
Background="#dd514c"/>
</Grid>
</SplitView.Pane>
<SplitView.Content>
<Grid>
<Frame x:Name="rootFrame"/>
<Button Name="HamburgerBtn"
Style="{StaticResource ResourceKey=appButtonStyle}"
VerticalAlignment="Center"
HorizontalAlignment="Left"
Background="Black"
Opacity=".4"
Click="HamburgerBtn_Click">
<Image Source="ms-appx:///Assets/paneBtn.png" Height="300" Width="20"/>
</Button>
</Grid>
</SplitView.Content>
</SplitView>
</Grid>
</Grid>
我设法通过覆盖 app.xaml.cs 中的“OnLaunched”,使应用程序中的所有页面都可以访问这个“splitview”:
var rootControl = Window.Current.Content as SplitViewRoot;
if (rootControl == null)
{
// Create a Frame to act as the navigation context and navigate to the first page
rootControl = new SplitViewRoot();
rootControl.RootFrame.NavigationFailed += OnNavigationFailed;
if (e.PreviousExecutionState == ApplicationExecutionState.Terminated)
{
//TODO: Load state from previously suspended application
}
// Place the frame in the current Window
Window.Current.Content = rootControl;
}
if (rootControl.RootFrame.Content == null)
{
// When the navigation stack isn't restored navigate to the first page,
// configuring the new page by passing required information as a navigation
// parameter
rootControl.RootFrame.Navigate(typeof(LoginPage), e.Arguments);
}
Window.Current.Activate();
问题是应用程序中有一个“登录页面”,它的页面中不应该有这个“拆分视图”。所以基本上我希望我的所有页面都可以访问“splitview”,但“LoginPage”除外。有人知道该怎么做吗?任何建议表示赞赏!
解决方案
推荐阅读
- python - 如何在python中为多个图形制作动画
- algorithm - 如果给定 n 组相对唯一的向量元素,确定全局唯一性的最快算法是什么?
- python - Python/MySQL - 只获取 5 行查询,如果用户按下一个字母,它会显示接下来的 5 行,依此类推
- javascript - chartjs - 反应数据没有到达 x 轴的末端
- maven - wso2 am 3.2 自定义 osgi 部署失败
- p5.js - 如何在 p5js 中获得带有视口的可缩放图像?
- kubernetes - ArgoCD 提供集群并同步
- python - 熊猫根据字典中的值选择行
- core-data - CoreData 的可观察对象 - 'NSSet?' 类型的值 没有下标
- python - 通过函数迭代列表不断返回 Nonetype