3

Yesterday I tested SVG support in WPF app (.Net Core 3.0 or/and .Net Framework 4.8) and none seems to support an Image xaml tag with an .svg ressource, while UWP project does support it.

Does anyone know when SVG will be supported in WPF project?

  • I have VS 2019 16.3.6 (the most recent)
  • I don't want to convert it. I would like (prefer) to use the same technology as the one used in UWP where SVG is displayed into Directx by the OS directly.
  • I thought unification of .net framework into Core would have brings us SVG support.

Sample code WPF with .Net framework 4.8:

    <Window x:Class="WpfAppTestSvg.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfAppTestSvg"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Image Source="Images\w.svg" Width="200" Height="200"></Image>
    </Grid>
</Window>

Sample code WPF with Core .Net 3.0

    <Window x:Class="WpfAppWithDotNetCore.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfAppWithDotNetCore"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Image Source="Images\w.svg"></Image>
    </Grid>
</Window>
sergiol
  • 4,122
  • 4
  • 47
  • 81
Eric Ouellet
  • 10,996
  • 11
  • 84
  • 119
  • You can convert SVG to Path data and the use it for drawing. [this](https://stackoverflow.com/questions/3526366/wpf-what-is-the-correct-way-of-using-svg-files-as-icons-in-wpf) is a thread for that – Pavel Anikhouski Oct 24 '19 at 13:20
  • "*Does anyone know when SVG will be supported in WPF project?*" Probably never natively. There are however third party libraries. – Clemens Oct 24 '19 at 13:34
  • @Pavel, Thanks, I don't want to convert it, I would like to use native SVG if possible in order to to benefits of quick rendering due to recent introduction of SVG support into Windows itself (which is used in UWP). – Eric Ouellet Oct 24 '19 at 14:12
  • @Clemens, Thanks!, although it could be a nice alternative, external library are problably a lot slower than UWP SvgImageSource which benefits of the new SVG support in recent update of the OS of Windows 10. – Eric Ouellet Oct 24 '19 at 14:14
  • I recommend a Nuget WPF library "SVG2XML". However, it only supports .net framework but not .net core . – Melon NG Oct 25 '19 at 06:29

1 Answers1

-2

Visit https://github.com/BerndK/SvgToXaml

you can use SvtToXaml get DrawingImage like this:

<DrawingImage x:Key="____3_01DrawingImage">
            <DrawingImage.Drawing>
                <DrawingGroup ClipGeometry="M0,0 V89 H230 V0 H0 Z">
                    <GeometryDrawing Brush="#FFD1D1D1" Geometry="F1 M230,89z M0,0z M222.5,80L222.5,80 14.1,80 14.1,77.6 15.1,77.6 15.1,79 221.5,79 221.5,11.6 215.8,11.6 215.8,10.6 222.5,10.6z" />
                    <DrawingGroup>
                        <GeometryDrawing Brush="#FF4AC0E0">
                            <GeometryDrawing.Geometry>
                                <RectangleGeometry RadiusX="0" RadiusY="0" Rect="9.7,7.7,209.3,69.9" />
                            </GeometryDrawing.Geometry>
                        </GeometryDrawing>
                    </DrawingGroup>
                </DrawingGroup>
            </DrawingImage.Drawing>
        </DrawingImage>
Retc
  • 1