【问题标题】:PathGeometry in ResourceDictionaryResourceDictionary 中的 PathGeometry
【发布时间】:2016-12-07 14:43:51
【问题描述】:

在 WPF 中,我曾经在 ResourceDictionary 中有我的矢量图标,如下所示:

<PathGeometry x:Key="BackIconGeometry">M9.5,0 L16,0 8.75,7 22,7 22,11 8.75,11 16,18 9.5,18 0,9 z</PathGeometry>

并像这样从应用程序中引用它:

<Path Data="{StaticResource BackIconGeometry}" Style="..." />

在 UWP 中出现错误:

“字符串”类型的值不能添加到集合或字典中 'PathFigureCollection' 类型的

如何将我的图标数据存储在资源字典中?我想避免将它们存储为&lt;Style TargetType="Path" /&gt;,因为我想为图标使用不同的样式

【问题讨论】:

    标签: xaml uwp


    【解决方案1】:

    您的路径是用于绑定的实际字符串值,因此不要使用 PathGeometry 在资源字典中使用 x:String

    <Application.Resources>
        <x:String x:Key="BackIconGeometry">M9.5,0 L16,0 8.75,7 22,7 22,11 8.75,11 16,18 9.5,18 0,9 z</x:String>
    </Application.Resources>
    

    在 XAML 中你可以像下面这样使用。

    <Path Data="{StaticResource BackIconGeometry}" />
    

    【讨论】:

    • 哦,在我问之前我已经尝试过了,但是我忘了包括资源字典。我的坏...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-09-08
    • 2013-02-17
    • 1970-01-01
    • 2012-12-03
    相关资源
    最近更新 更多