Answer the question
In order to leave comments, you need to log in
How to work with SVG in WPF?
In the ViewModel I get svg as a string. How to bind it in View as an icon? Do I need a converter or can I somehow do without it?
Answer the question
In order to leave comments, you need to log in
Used
SharpVectors .
In the ViewModel I save to the svg file.
In xaml markup I use the SvgViewbox component.
To bind the path to Source added AttachedProperty
public class SvgViewboxAttachedProperties : DependencyObject
{
public static string GetSource(DependencyObject obj)
{
return (string)obj.GetValue(SourceProperty);
}
public static void SetSource(DependencyObject obj, string value)
{
obj.SetValue(SourceProperty, value);
}
private static void OnSourceChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
{
var svgControl = obj as SvgViewbox;
if (svgControl != null)
{
svgControl.Source = new System.Uri((string) e.NewValue);
}
}
public static readonly DependencyProperty SourceProperty =
DependencyProperty.RegisterAttached("Source",
typeof(string), typeof(SvgViewboxAttachedProperties),
new PropertyMetadata(null, OnSourceChanged));
}
<svgc:SvgViewbox common:SvgViewboxAttachedProperties.Source="{Binding IconPath}" />
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question