PathGeometry in ResourceDictionary

拟墨画扇 提交于 2019-12-11 06:25:40

问题


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="..." />

In UWP I'm getting error:

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

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


回答1:


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>

and in XAML you can use like below.

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


来源:https://stackoverflow.com/questions/41020372/pathgeometry-in-resourcedictionary

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