0

I've an svg file, contents are two groups of paths and some polygons which I should use as an input to image source.(svg contents:Two gids which consits collection of path and polygon shapes)

I extracted paths and polygons as below from svg and created geometry groups

   <GeometryGroup x:Key="icon-2"
  PresentationOptions:Freeze="True" >
        <PathGeometry Figures="M0.664201681.........." />
        <PathGeometry Figures="M0.664201681.........." />
    <PathGeometry Figures="M0.664201681.........." />
    </GeometryGroup>

    <GeometryGroup x:Key="icon-1"
  PresentationOptions:Freeze="True" >
        <PathGeometry Figures="M0.664201681.........." />
        <PathGeometry Figures="M0.664201681.........." />
    <PathGeometry Figures="M0.664201681.........." />
    </GeometryGroup>

I've some polygons as below in svg file

<polygon id="Shape" fill="#0067B1" points="42.1853782 0.249018403 0.249008405........"></polygon>

I tried adding the above polygon, but I got an error says Polygon is not supported.

<Style
    x:Key="myLogoStyle"
    TargetType="Image">
    <Setter
        Property="Source">
<Setter.Value>
        <DrawingImage
     PresentationOptions:Freeze="True" >
            <DrawingImage.Drawing>
                <DrawingGroup>
                    <GeometryDrawing Brush="#FFFFFF"
      Geometry="{StaticResource icon-2}" />
                    <GeometryDrawing Brush="#000000"
      Geometry="{StaticResource icon-1}" />
                </DrawingGroup>
            </DrawingImage.Drawing>
        </DrawingImage>
     </Setter.Value>
    </Setter>
    </style>

Can someone please suggest, is there any way to give the combination of path and shapes as an input to image source.?

MKR Harsha
  • 105
  • 9
  • Possible duplicate of [Show Drawing.Image in WPF](http://stackoverflow.com/questions/10077498/show-drawing-image-in-wpf) – Sinatr Mar 20 '17 at 15:20
  • It seems this is your attempted solution to display SVG? I am not sure with which duplicate to close this question: [display svg](http://stackoverflow.com/q/26151257/1997232), [draw geometrygroup](http://stackoverflow.com/q/6434284/1997232), ... or maybe something else. – Sinatr Mar 20 '17 at 15:24
  • I would like to give image source as only geometry path/shapes. We can't use external svg/png direct. – MKR Harsha Mar 20 '17 at 18:00
  • We can only use the extracted geometry from svg files. Can be done with canvas but it would be better if i got it with image control itself. – MKR Harsha Mar 20 '17 at 18:10

1 Answers1

0

do not use an image control, but ContentPresenter then put your resources into viewbox/canvas and it works

<Style x:Key="MetroButton" TargetType="Button">
    <Setter Property="MinHeight" Value="30"/>
    <Setter Property="Visibility" Value="Visible"/>
    <Setter Property="Foreground" Value="{DynamicResource Foreground}"/>
    <Setter Property="Background" Value="{DynamicResource BackgroundNormal}"/>
    <Setter Property="BorderBrush" Value="{DynamicResource BorderBrushNormal}"/>
    <Setter Property="Template">
        <Setter.Value>
            <ControlTemplate TargetType="Button">
                <Border SnapsToDevicePixels="True"
                        BorderThickness="1"
                        Margin="{TemplateBinding Padding}" 
                        BorderBrush="{TemplateBinding BorderBrush}" 
                        Background="{TemplateBinding Background}">
                    <Grid SnapsToDevicePixels="True">
                        <ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center"/>
                    </Grid>
                </Border>

and the ressource

<Canvas x:Shared="False" Width="48" Height="48" Clip="F1 M 0,0L 48,0L 48,48L 0,48L 0,0" x:Key="appbar_add">
    <Path Width="24" Height="24" Canvas.Left="12" Canvas.Top="12" Stretch="Fill" Fill="Black" Data="F1 M 22,12L 26,12L 26,22L 36,22L 36,26L 26,26L 26,36L 22,36L 22,26L 12,26L 12,22L 22,22L 22,12 Z " />
</Canvas>
GCamel
  • 612
  • 4
  • 8