0

在我的主页上,我有一个带有两个按钮的拆分视图。按钮导航到其他页面。其他页面不包含拆分视图。如何在不重复代码的情况下在所有页面之间共享 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="&#xE700;" Width="50" Height="50" Background="Transparent" Click="HamburgerButton_Click"/>

            <StackPanel Orientation="Horizontal">
                <Button x:Name="LocatieButton" FontFamily="Segoe MDL2 Assets" Content="&#xE825;" 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="&#xE10F;" 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));
    }
}
4

1 回答 1

0

您可以创建自己的Frame内部SplitView.Content并使用它来显示页面:

<SplitView.Content>
    <Frame x:Name="Fr_MainFrame"/>
</SplitView.Content>

然后代替this.FrameFr_MainFrame用于导航:

Fr_MainFrame.Navigate(typeof(ParkeerplaatsPage));
于 2017-05-24T16:25:56.997 回答