Skip to content

Provide a version of SvgImage that directly inherits from ImageSource #314

Description

@edwwsw

You're probably aware of this, but since SvgImage uses extension markup you can't wrap it as a key'ed ResourceDictionary resource and use that resource elsewhere.

<ResourceDictionary 
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:svg="http://sharpvectors.codeplex.com/runtime/"
    xmlns:svgc="http://sharpvectors.codeplex.com/svgc/">
...
<svgc:SvgIcon x:Key="MonitorIcon"  UriSource="Images/MonitorRun.svg"/>

Usage point

<UserControl 
    x:Class="ExampleClass"
    ...
     <Image Source="{DynamicResource MonitorIcon}" Height="24" Width="24"/>

Error message at the usage point is: The resource 'MonitorIcon' has an incompatible type.

I looked at what it would take to fix this and kind of understand why you went the extension route. Neither ImageSource nor DrawingImage can be derived from. One has a internal constructor that needs a parameter, the other class is sealed.

However, you might be able to either Directly derive a class from BitmapSource or use WritableBitmap to create a custom ImageSource. WriteableBitmap looking like it might be more appropriate.

https://learn.microsoft.com/en-us/dotnet/api/system.windows.media.imaging.writeablebitmap?view=windowsdesktop-10.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions