Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why can't I define a Geometry with a Transform in XAML?

I am trying to create a ResourceDictionary á la this answer that contains StreamGeometries that have Transforms set:

<ResourceDictionary>
    <StreamGeometry x:Name="Chevrons">
        <StreamGeometry.Transform>
            <TranslateTransform X="20" Y="120"/>
        </StreamGeometry.Transform>
        M21.750001,94.749999 L34.000002,117.66218 30.625003,133.62501 17 [...]
    </StreamGeometry>
</ResourceDictionary>

However, I get the following error:

1: Cannot add content to an object of type "StreamGeometry".

and

2: TypeConverter syntax error encountered while processing initialization string '{PathData}'. Element attributes are not allowed on objects created via TypeConverter.

So I tried it with a PathGeometry and got this error:

The specified value cannot be assigned to the collection. The following type was expected: "PathFigure".

Is there any way to do apply a transform to a Geometry in XAML code? Or do I just have to do it via code?

like image 250
Kian Avatar asked Oct 21 '25 17:10

Kian


1 Answers

You may write it like this:

<PathGeometry x:Key="Chevrons">
    <PathGeometry.Transform>
        <TranslateTransform X="20" Y="120"/>
    </PathGeometry.Transform>
    <PathGeometry.Figures>
        M21.750001,94.749999 L34.000002,117.66218 30.625003,133.62501 ...
    </PathGeometry.Figures>
</PathGeometry>

or like this:

<PathGeometry x:Key="Chevrons"
    Figures="M21.750001,94.749999 L34.000002,117.66218 30.625003,133.62501 ...">
    <PathGeometry.Transform>
        <TranslateTransform X="20" Y="120"/>
    </PathGeometry.Transform>
</PathGeometry>
like image 71
Clemens Avatar answered Oct 23 '25 08:10

Clemens



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!