0

我在 Windows RT 和 UWP 应用程序开发领域相对较新,现在我有一个 Windows 8.1 项目,我想在其中使用 Prism。该应用程序(一个问答游戏)由三个页面组成,我想实现一个在所有页面上都相同的页眉。我进行了很多搜索,但没有找到任何解决方案,如何使用 prism 为商店应用程序实现这一点。如果没有 Prism,我可以导航到主页,然后调用函数“myTargetFrame.Navigate(typeOf(secondPage));” 但是我怎么能在棱镜的情况下做到这一点,这可能吗?

预先感谢您的帮助

4

1 回答 1

0

这是你如何做到的。

public sealed partial class App : PrismUnityApplication
{
    public App()
    {
        InitializeComponent();
    }

    protected override UIElement CreateShell(Frame rootFrame)
    {
        var masterPage = Container.Resolve<MasterPage>();
        masterPage.MyFrame = rootFrame;
        return masterPage;
    }

    protected override Task OnLaunchApplicationAsync(LaunchActivatedEventArgs args)
    {
        NavigationService.Navigate(Keys.MainPage, null);
        return Task.FromResult(true);
    }
}

接着。

public sealed partial class MasterPage : Page
{
    public MainPage()
    {
        InitializeComponent();
        NavigationCacheMode = NavigationCacheMode.Enabled;
    }

    public Frame MyFrame
    {
        get { return (Frame)GetValue(MyFrameProperty); }
        set { SetValue(MyFrameProperty, value); }
    }
    public static readonly DependencyProperty MyFrameProperty =
        DependencyProperty.Register(nameof(MyFrame), typeof(Frame), 
            typeof(MasterPage), new PropertyMetadata(null));
}

接着。

<Page>
    <Grid>
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition />
        </Grid.RowDefinitions>
        <CommandBar Grid.Row="0" Content="Header" />
        <ContentPresenter Grid.Row="1" Content="{x:Bind MyFrame, Mode=OneWay}" />
    </Grid>
</Page>

再次,我建议你看看@ http://aka.ms/template10

祝你好运。

于 2016-02-07T04:17:32.340 回答