0

I'm saving an svg image as xaml string in a database. Next I record this xaml string in a property of a class (MyClass.XamlString) .

On my form I have a Canvas, and I want MyClass.XamlString to be the child of the canvas.

This is what I have:

        Dim MyBinding As New Binding("XamlString")
        MyBinding.Source = MyClass
        MyBinding.Converter = New clsXamlToCanvasConverter
        CanvasOnForm.SetBinding(ContentPresenter.ContentProperty, MyBinding) 

and

Friend Class clsXamlToCanvasConverter
Implements IValueConverter

Public Function Convert(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.Convert
    Dim ConvertedCanvas As Canvas = System.Windows.Markup.XamlReader.Parse("<Canvas xmlns=""http://schemas.microsoft.com/winfx/2006/xaml/presentation"" xmlns:x=""http://schemas.microsoft.com/winfx/2006/xaml"">" & value & "</Canvas>")
    Return ConvertedCanvas
End Function

Public Function ConvertBack(value As Object, targetType As Type, parameter As Object, culture As Globalization.CultureInfo) As Object Implements IValueConverter.ConvertBack
    Throw New NotImplementedException
End Function
End Class

In debugging I see the clsXamlToCanvasConverter creates a canvas with children from the xaml string, this is working correctly although you might say the extra canvas is redundant.

My guess is this is where I'm going wrong: CanvasOnForm.SetBinding(ContentPresenter.ContentProperty, MyBinding)

The code runs fine, the problem is I don't see the image displayed.

I've been searching a lot on this and I've seen this post WPF What is the correct way of using SVG files as icons in WPF , but apparently this hasn't helped me out.

Any ideas?

Community
  • 1
  • 1
  • If `CanvasOnForm` is actually a Canvas, the binding won't work because Canvas has no Content property. You may use a ContentControl or ContentPresenter instead. – Clemens Oct 26 '15 at 11:19
  • Thank you, that solved it. If you enter it as answer I can mark it as correct answer. – user3891203 Oct 26 '15 at 16:24

0 Answers0