如何在UWP中使用资源字典中的路径数据

adm*_*tDK 5 xaml win-universal-app

这是微不足道的事情,但它不起作用.

我有这样的东西(它在自己的文件夹中)

<ResourceDictionary>
    <Path x:Key="Test"
          Stroke="Black"
          Fill="Gray" 
          Data="M 10,100 C 10,300 300,-200 300,100" />
</ResourceDictionary>
Run Code Online (Sandbox Code Playgroud)

现在我想用它

<Page>
    <Page.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergeDictionaries>
                <ResourceDictionary Source="MyFolder/MyResourceDictionary.xaml/>
            </ResourceDictionary.MergeDictionaries>
        </ResourceDictionary>
    </Page.Resources>
    <ContentPresenter Content="{StaticResource Test}"/>
<Page/>
Run Code Online (Sandbox Code Playgroud)

这会引发异常,但我不明白为什么.在wpf中完全相同的场景工作正常.

And*_*pka 5

那这个解决方案呢?

声明你的 GeometryData

<x:String x:Key="TestPathGeomerty">M 10,100 C 10,300 300,-200 300,100</x:String>
Run Code Online (Sandbox Code Playgroud)

Path改用ContentPresenter

<Path Data="{StaticResource TestPathGeomerty}"
      Fill="Red"/>
Run Code Online (Sandbox Code Playgroud)

  • 我收到 XAML 智能感知错误“资源“TestPathGeomerty”的类型不兼容”。我的目标是秋季创作者更新。 (2认同)

Fre*_*lad 5

Path.Data 属性是类型Geometry,因此将其定义为 aGeometry而不是 astring

<Geometry x:Key="TestPathGeomerty">M 10,100 C 10,300 300,-200 300,100</Geometry>

<Path Data="{StaticResource TestPathGeomerty}"
      Fill="Red"/>
Run Code Online (Sandbox Code Playgroud)