在我的主页上,我有一个带有两个按钮的拆分视图。按钮导航到其他页面。其他页面不包含拆分视图。如何在不重复代码的情况下在所有页面之间共享 splitview?以便在每个页面上都可以使用拆分视图。
MainPage.xaml:
<SplitView x:Name="MySplitView" DisplayMode="CompactOverlay" IsPaneOpen="False" CompactPaneLength="50" OpenPaneLength="170">
<SplitView.Pane>
<StackPanel Background="Gray">
<Button x:Name="HamburgerButton" FontFamily="Segoe MDL2 Assets" Content="" Width="50" Height="50" Background="Transparent" Click="HamburgerButton_Click"/>
<StackPanel Orientation="Horizontal">
<Button x:Name="LocatieButton" FontFamily="Segoe MDL2 Assets" Content="" Width="50" Height="50" Background="Transparent" Click="LocatieButton_Click"/>
<TextBlock Text="Locatie" FontSize="18" VerticalAlignment="Center" />
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button x:Name="RDWButton" FontFamily="Segoe MDL2 Assets" Content="" Width="50" Height="50" Background="Transparent" Click="RDWButton_Click"/>
<TextBlock Text="Parkeren" FontSize="18" VerticalAlignment="Center" />
</StackPanel>
</StackPanel>
</SplitView.Pane>
<SplitView.Content>
<Grid>
<TextBlock Text="Basic" FontSize="54" Foreground="White" HorizontalAlignment="Center" VerticalAlignment="Center"/>
</Grid>
</SplitView.Content>
</SplitView>
MainPage.xaml.cs:
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent();
}
private void HamburgerButton_Click(object sender, RoutedEventArgs e)
{
MySplitView.IsPaneOpen = !MySplitView.IsPaneOpen;
}
private void LocatieButton_Click(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(LocatiePage));
}
private void RDWButton_Click(object sender, RoutedEventArgs e)
{
this.Frame.Navigate(typeof(ParkeerplaatsPage));
}
}