1

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.

Rand Random
  • 7,300
  • 10
  • 40
  • 88
Cleo42
  • 11
  • 2
  • 1
    You should have an ItemsControl that is bound to a collection of objects that represent each shape, e.g. like shown here: https://stackoverflow.com/a/40720205/1136211 – Clemens Dec 12 '17 at 10:27
  • Alternatively write a Binding Converter that combines a collection of input geometries to an output geometry (e.g. a GeometryGroup). – Clemens Dec 12 '17 at 10:34
  • Hi Clemens, thanks for your suggestions. I will give it a look – Cleo42 Dec 12 '17 at 11:40

0 Answers0