NControl.Controls icon indicating copy to clipboard operation
NControl.Controls copied to clipboard

SvgImage: How to specify SvgAssembly or SvgAssemblyType in XAML

Open opcodewriter opened this issue 9 years ago • 3 comments

What's the cleanest way? I wish that these properties had a type converter to allow that.

opcodewriter avatar Aug 05 '16 07:08 opcodewriter

Weird thing that this doesn't work (SVG is not displayed): SvgAssemblyType="{x:Type vm:MyViewModel}"

Doing the same thing by code works.

opcodewriter avatar Aug 05 '16 07:08 opcodewriter

I spent an incredibly amount of time on this... Maybe this is helpful for someone else too.

The issue with not updating when using in XAML is because in the propertyChanged callback, it calls ctrl.SvgAssemblyType = (Type)newValue; but in the getter the getter value is already the same with property, therefore UpdateSvg and Invalidate are not called. An easy fix is to explicitly call UpdateSvg and Invalidate on each propertyChanged.

But the real issue I think is that by default the SvgImage should use the current assembly, such that there shouldn't be necessary to set it explicitly.

        public static BindableProperty SvgAssemblyTypeProperty =
            BindableProperty.Create(nameof(SvgAssemblyType), typeof(Type), typeof(SvgImage), Application.Current.GetType(),
                propertyChanged: (bindable, oldValue, newValue) => {
                    var ctrl = (SvgImage)bindable;
                    ctrl.SvgAssemblyType = (Type)newValue;
                });

Another thing: I don't understand why all the 3 bindable properties are two-way, it doesn't make sense to me, the control doesn't change any of them.

opcodewriter avatar Aug 05 '16 08:08 opcodewriter

You are welcome to fork the project and try to if you can fix this and submit a pull request if possible.

chrfalch avatar Feb 11 '17 11:02 chrfalch