0

I'm having a similar issue to the one discussed here - Using Geometry resources in XAML - but I did not find answer there. I have a page in UWP, which looks like this:

<Page.Resources>
        <GeometryGroup x:Key="Geometry">
            <RectangleGeometry Rect="0 ,0 100 ,100"></RectangleGeometry>
            <EllipseGeometry Center="150, 50" RadiusX="35" RadiusY="25"></EllipseGeometry>
        </GeometryGroup>
    </Page.Resources>

    <Canvas x:Name="canMain" >
        <Path Fill="Yellow" Stroke="Blue" Margin="5" Canvas.Top="10" Canvas.Left="10"
Data="{StaticResource Geometry}">
        </Path>
        <Path Fill="Green" Stroke="Blue" Margin="5" Canvas.Top="150" Canvas.Left="10"
Data="{StaticResource Geometry}">
        </Path>
    </Canvas>

The sample code is taken from a WPF book, where it's supposed to work. On UWP the app throws a run-time exception (meaning the app builds fine) of type Windows.UI.Xaml.Markup.XamlParseException with a message: "Failed to assign to property 'Windows.UI.Xaml.Shapes.Path.Data" The error points to this line:

    <Path Fill="Yellow" Stroke="Blue" Margin="5" Canvas.Top="10" Canvas.Left="10"
Data="{StaticResource Geometry}">

In particular this piece Data="{StaticResource Geometry}" - do you have any ideas please? Thank you!

If I try this example, then it works. If I rewrite the example like this:

<Page.Resources>
        <GeometryGroup x:Key="myGeometry">
            <EllipseGeometry Center="50,50" RadiusX="50" RadiusY="50"/>
            <RectangleGeometry Rect="0,0,100,100" />
        </GeometryGroup>

    </Page.Resources>

    <Path Fill="Gold" Stroke="Black" StrokeThickness="1" Data="{StaticResource ResourceKey=myGeometry}">
    </Path>

I get the same exception.

  • 1
    i think you are binding a GeometryGroup to Data that you must bind a Geometry to Data – Katana Jan 25 '20 at 16:04
  • @Mahdi - thank you, however GeometryGroup inherits from Geometry, so GeometryGroup is Geometry. So everything should be fine from the perspective. – Vladimír Gregor Jan 25 '20 at 16:57
  • Does it work if you copy and paste the `GeometryGroup` directly in the `Data` tags instead of using `StaticResource`? (like in [this example](https://learn.microsoft.com/en-us/uwp/api/windows.ui.xaml.shapes.path#examples)) – Batesias Jan 25 '20 at 18:49
  • @Batesias - yes, then it works. See my edited question. Thank you. – Vladimír Gregor Jan 26 '20 at 13:39
  • 1
    Interesting, it's probably a bug in UWP... I get an `ArgumentException` when I set the `Path.Data` property in code behind. ![screenshot](https://imgur.com/a/QqZIaXh) There's probably some limitation that UWP has that WPF doesn't (and that makes sense since they're not the same thing). – Batesias Jan 26 '20 at 16:33
  • @VladimírGregor I could reproduce your issue and I have report this to related team, and you could also post this issue in [microsoft-ui-xaml](https://github.com/microsoft/microsoft-ui-xaml/issues) github. – Nico Zhu Jan 27 '20 at 05:57
  • 1
    @NicoZhu-MSFT - thank you for your attention and feedback gentlemen. I'm surprised! I thought I was doing something wrong. I reported the issue here: https://github.com/microsoft/microsoft-ui-xaml/issues/1909 – Vladimír Gregor Jan 29 '20 at 21:08
  • @Batesias - thank you for your feedback. I reported the issue. – Vladimír Gregor Jan 29 '20 at 21:09

0 Answers0