How to bind PathGeometry objects in MVVM

706 Views Asked by At

Imagine an application where the user can type in some text and based on the text input different symbols are shown on an image.

I am looking for a way generate a list of Path objects and bind this list in XAML to show the path objects on top of another path-image. I.e. I have a simple image of a house, the user type in text like: "ball on roof, flower in window, shovel in garden" In the ViewModel I will analyze this text and generate a path Circle for the ball, a path Star for the flower and a path Square for the shovel.

I think these objects should be put in a List and in XAML bind to this list.

The "house" is drawn like this:

<Border Grid.Column="1" CornerRadius="10" BorderBrush="Black" BorderThickness="0.3" Margin="5,0,0,0" Grid.RowSpan="2" Padding="5">
    <Viewbox xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" Stretch="Uniform">
        <Grid RenderTransformOrigin="0.5,0.5">
            <Grid.RenderTransform>
                <TransformGroup>
                    <ScaleTransform ScaleY="-1" ScaleX="1"/>
                    <SkewTransform AngleY="0" AngleX="0"/>
                    <RotateTransform Angle="0"/>
                    <TranslateTransform/>
                </TransformGroup>
            </Grid.RenderTransform>

            <Path Fill="Black" Data="{StaticResource Path1}"/>
            <Path Fill="Black" Data="{StaticResource Path2}"/>
            <Path Fill="Black" Data="{StaticResource Path3}"/>
            <Path Fill="Black" Data="{StaticResource Path4}"/>
            ...

        </Grid>
    </Viewbox>
</Border>

After the all the "Path" I imagine I would use a CombinedGeometry and bind to the VM List. But I am not sure about this part.

0

There are 0 best solutions below