Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

SvgImage Exception when setting SvgPath Property late #60

Open
franzdevel opened this issue Feb 15, 2017 · 0 comments
Open

SvgImage Exception when setting SvgPath Property late #60

franzdevel opened this issue Feb 15, 2017 · 0 comments

Comments

@franzdevel
Copy link

franzdevel commented Feb 15, 2017

I've run into exceptions when instantiating an SvgImage as follows:

sampleButton = new SvgImage
{
    IsVisible = false,
    SvgAssembly = typeof(App).GetTypeInfo().Assembly,
    HeightRequest = 44,
    WidthRequest = 44,
};

And, at a later point in time:

sampleButton.IsVisible = true;
sampleButton.SvgPath = "MyPath.MyImage.svg";

The SvgImage.RenderSvgToCanvas() method is invoked even though the SvgImage is initially invisible. The method fails because LoadedGraphic is null:

public IImageCanvas RenderSvgToCanvas (...)
{
    var originalSvgSize = LoadedGraphic.Size; // Exception because LoadedGraphic = null
    var finalCanvas = createPlatformImageCanvas (outputSize, finalScale);
    ...
}

A possible solution might be:

public IImageCanvas RenderSvgToCanvas (...)
{
    var finalCanvas = createPlatformImageCanvas(outputSize, finalScale);
    if (LoadedGraphic == null)
    {
        return finalCanvas;
    }
    var originalSvgSize = LoadedGraphic.Size;
    ...
}
@franzdevel franzdevel changed the title SvgImage exception when setting SvgPath property late SvgImage Exception when setting SvgPath Property late Feb 15, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant