【问题标题】:XamlParseException when using FontIcon from resources in Universal App使用 Universal App 中资源中的 FontIcon 时出现 XamlParseException
【发布时间】:2014-06-06 16:08:21
【问题描述】:

我正在尝试将我在 appbar 中使用的按钮的 FontIcons 放在资源中。代码如下:

<Page.Resources>
    <FontFamily x:Key="IconsFont">/Assets/iconfont.ttf#iconfont</FontFamily>
    <FontIcon x:Key="LogoutIcon" FontFamily="{StaticResource IconsFont}" Glyph="&#xe600;" FontSize="35" />
  </Page.Resources>
<Page.BottomAppBar>
  <CommandBar>
    <AppBarButton Icon="Find" Label="search" Command="{Binding SearchCommand}" Visibility="{Binding SearchCommandVisibility}"/>
    <AppBarButton Label="logout" Command="{Binding LogoutCommand}" Icon="{StaticResource LogoutIcon}" />
  </CommandBar>
</Page.BottomAppBar>

在设计器中看起来一切正常,图标显示正确。但是当我启动应用程序时,我收到带有通用错误文本的 XamlParseException:“无法分配给属性 '%0'”

如果我将 FontIcon 从资源中取出,它也可以正常工作。

有什么想法吗?

【问题讨论】:

    标签: windows-phone appbar win-universal-app


    【解决方案1】:

    试试,

    <Page.BottomAppBar>
        <CommandBar>
            <AppBarButton Icon="Find" Label="search"/>
            <AppBarButton Label="logout">
                <AppBarButton.Icon>
                    <FontIcon FontFamily="{StaticResource IconsFont}" Glyph="&#xe600;" FontSize="35"/>
                </AppBarButton.Icon>
            </AppBarButton>
        </CommandBar>
    </Page.BottomAppBar>
    

    并从页面资源中删除&lt;FontIcon x:Key="LogoutIcon" FontFamily="{StaticResource IconsFont}" Glyph="&amp;#xe600;" FontSize="35" /&gt;

    【讨论】:

    • 这行得通,但这不是我需要的。我需要将图标保留在资源中。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-03-18
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多