将 NavigationView 添加到 XAML:"Cannot find a Resource with the Name/Key NavigationViewItemDefaultStyle"

Adding NavigationView to XAML: "Cannot find a Resource with the Name/Key NavigationViewItemDefaultStyle"

我是 Windows 开发的新手,我正在尝试使用新的 NavigationView 控件(目前处于测试阶段)创建应用程序。 我为我的项目安装了 16190 SDK。我的电脑是 运行 v.1703,内部版本 16215.1000.

但是,当我将 NavigationView 标记添加到我的 XAML 文件时,我的项目不再构建,出现以下 XamlParseException 异常:

"Cannot find a Resource with the Name/Key NavigationViewItemDefaultStyle"

我尝试使用导航视图作为我页面的根元素,并且我在项目中没有额外的代码。 可能是什么问题呢?是否需要采取任何特定步骤才能使用 beta SDK 进行开发?

这是 16215 中的 bug,如果您回滚到 16199,它应该会再次工作。

请注意,您需要在代码隐藏中声明 NavigationViewItems 才能正常工作,不幸的是,这只是另一个错误。

<NavigationView x:Name="MyNavigationView"
                Header="Fluent Layout"
                AlwaysShowHeader="False"
                IsSettingsVisible="True">
    <Frame x:Name="RootFrame"
           Margin="24" />
</NavigationView>

public MainPage()
{
    InitializeComponent();

    // The following cannot be done in XAML in this build yet.
    MyNavigationView.AddMenuItem(Symbol.AllApps, "All Applications", (s, e) => RootFrame.Navigate(typeof(AppsPage)), true);
    MyNavigationView.AddMenuItem(Symbol.Video, "Games", (s, e) => RootFrame.Navigate(typeof(GamesPage)));
    MyNavigationView.AddMenuItem(Symbol.Calendar, "Calendar", (s, e) => RootFrame.Navigate(typeof(CalendarPage)));
    MyNavigationView.AddMenuItemSeparator();
    MyNavigationView.AddMenuItem(Symbol.Admin, "My Account", (s, e) => RootFrame.Navigate(typeof(AccountPage)));

    MyNavigationView.SettingsInvoked += (s, e) => RootFrame.Navigate(typeof(SettingsPage));
    RootFrame.Navigate(typeof(AppsPage));
}

一旦两个错误都得到修复,我将更新答案。