Unknown type 'AppBarButton' in XML namespace - Windows 8 Store App XAML, issues adding app bars

放肆的年华 提交于 2020-01-13 10:56:08

问题


I'm new to developing Windows 8 apps, and am having trouble getting my XAML file to recognise generated code for adding AppBars and CommandBars.

I am getting the error "Unknown type [something] in XML namespace" for a number of elements I am trying to add, here is my example below:

If I re-open my solution this is temporarily displayed as a warning rather than an error. Also navigating to http://schemas.microsoft.com/winfx/2006/xaml/presentation just produces "The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.".

This is all default code. my class namespace (e.g. MyApp.MainPage) matches the MainPage code behind namespace. I am at a loss and have been battling this for hours. I also intermittently changes from this error to 'InitializeComponent' does not exist in the current context". I have spent hours on XAML permissions errors in the past few days and don't want to waste any more time with errors in default generated code! :(

EDIT: I have tried this on three different machines, using both Windows 8 and Windows 8.1, both new projects and the existing project I have described in this post.


回答1:


My guess is that you are using Visual Studio 2012 (Windows 8 apps). If so, you should use Button:

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

To use AppBarButton, you must use Visual Studio 2013 (Windows 8.1 apps):

<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>

Also, CommandBars are only available in Windows 8.1.



来源:https://stackoverflow.com/questions/19801040/unknown-type-appbarbutton-in-xml-namespace-windows-8-store-app-xaml-issues

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!