ResourceDictionary 中的 PathGeometry [英] PathGeometry in ResourceDictionary

查看:43
本文介绍了ResourceDictionary 中的 PathGeometry的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

In WPF I used to have my vector icons in ResourceDictionary like this:

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

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

and reference it from application like this:

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

在 UWP 中我收到错误:

In UWP I'm getting error:

'String' 类型的值不能添加到集合或字典中'PathFigureCollection' 类型

A value of type 'String' cannot be added to a collection or dictionary of type 'PathFigureCollection'

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

How can I store my icons data in resource dictionaries? I would like to avoid storing them as <Style TargetType="Path" /> since I would like to use different styles for the icons

推荐答案

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

Your Path is an actual string value that is used for Binding so instead of using PathGeometry use x:String in resource Dictionary.

<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 中,您可以像下面这样使用.

and in XAML you can use like below.

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

这篇关于ResourceDictionary 中的 PathGeometry的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆