T
T
TomYol2020-10-11 19:47:04
WPF
TomYol, 2020-10-11 19:47:04

How to insert a vector image into a WPF window?

It seems that you need to convert svg to xaml, I did it in inskape, but I don’t know what to do next. Can you suggest the simplest and most understandable way to insert a vector image on a form?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
Boris the Animal, 2020-10-24
@TomYol

The image can be enlarged (click or open in a new tab). XAML code is formatted with the XamlStyler extension.
5f9489198d002927078688.png

<Window
    x:Class="WpfVectorImage.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:icons="clr-namespace:WpfVectorImage.Icons"
    xmlns:local="clr-namespace:WpfVectorImage"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    Title="MainWindow"
    Width="800"
    Height="450"
    mc:Ignorable="d">
    <Grid>
        <icons:DumbbellIcon />
    </Grid>
</Window>

You can’t put an icon here that is in the screenshot, there are too many characters.
DumbbellIcon.xaml (icon)
<UserControl
    x:Class="WpfVectorImage.Icons.DumbbellIcon"
    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:local="clr-namespace:WpfVectorImage.Icons"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    d:DesignHeight="450"
    d:DesignWidth="800"
    mc:Ignorable="d">

    <Viewbox Stretch="Uniform">
        <Canvas
            Name="Layer_1"
            Width="512"
            Height="512">
            <Canvas.RenderTransform>
                <TranslateTransform X="0" Y="0" />
            </Canvas.RenderTransform>
            <Canvas.Resources />
            <Canvas Name="g79">
                <Canvas Name="g73">

                </Canvas>
            </Canvas>
        </Canvas>
    </Viewbox>
</UserControl>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question