如何在页面之间共享splitview?

时间:2017-05-24 14:48:13

标签: c# uwp splitview

在我的主页上,我有一个带有两个按钮的splitview。按钮导航到其他页面。其他页面不包含splitview。如何在没有代码重复的情况下在所有页面之间共享splitview?这样每个页面都可以使用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));
    }
}

1 个答案:

答案 0 :(得分:0)

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

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

然后代替this.Frame,您将使用Fr_MainFrame进行导航:

Fr_MainFrame.Navigate(typeof(ParkeerplaatsPage));
相关问题