XML命名空间中的未知类型“AppBarButton” - Windows 8 Store App XAML,发布添加应用栏的问题

时间:2013-11-05 23:18:20

标签: xaml windows-8 namespaces winrt-xaml

我是开发Windows 8应用程序的新手,我无法让我的XAML文件识别用于添加AppBars和CommandBars的生成代码。

我收到错误“XML名称空间中的未知类型[某事物]”我想要添加的许多元素,下面是我的示例:

Unknown type 'AppBarButton' in XML Namespace

如果我重新打开我的解决方案,这会暂时显示为警告而不是错误。导航到http://schemas.microsoft.com/winfx/2006/xaml/presentation只会产生“您要查找的资源已被删除,名称已更改或暂时不可用。”。

这是所有默认代码。我的类命名空间(例如MyApp.MainPage)与命名空间后面的MainPage代码匹配。我很茫然,并且已经和我斗争了好几个小时。我也间歇性地从这个错误更改为'InitializeComponent'在当前上下文中不存在“。我在过去几天花了数小时处理XAML权限错误,并且不想再浪费任何时间在默认生成的代码中出错! :(

编辑:我在三台不同的机器上尝试了这个,使用Windows 8和Windows 8.1,这两个新项目和我在本文中描述的现有项目。

1 个答案:

答案 0 :(得分:5)

我的猜测是你使用的是Visual Studio 2012(Windows 8应用程序)。如果是这样,您应该使用Button

<Page.TopAppBar>
    <AppBar>
        <StackPanel Orientation="Horizontal">
            <Button Style="{StaticResource AppBarButtonStyle}">A</Button>
            <Button Style="{StaticResource AppBarButtonStyle}">B</Button>
        </StackPanel>
    </AppBar>
</Page.TopAppBar>

要使用AppBarButton,您必须使用Visual Studio 2013(Windows 8.1应用程序):

<Page.TopAppBar>
    <AppBar>
        <StackPanel Orientation="Horizontal">
            <AppBarButton>
                <AppBarButton.Icon>
                    <FontIcon Glyph="A"/>
                </AppBarButton.Icon>
            </AppBarButton>
            <AppBarButton>
                <AppBarButton.Icon>
                    <FontIcon Glyph="B"/>
                </AppBarButton.Icon>
            </AppBarButton>
        </StackPanel>
    </AppBar>
</Page.TopAppBar>

此外,CommandBars仅适用于Windows 8.1。