簡體   English   中英

如何在頁面之間共享splitview?

[英]How to share splitview between pages?

在我的主頁上,我有一個帶有兩個按鈕的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));
    }
}

您可以在SplitView.Content創建自己的Frame並將其用於顯示頁面:

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

然后,代替this.Frame您將使用Fr_MainFrame進行導航:

Fr_MainFrame.Navigate(typeof(ParkeerplaatsPage));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM