Xamarin.Forms.Plugins icon indicating copy to clipboard operation
Xamarin.Forms.Plugins copied to clipboard

Width and height must be > 0 Exception

Open rupe120 opened this issue 8 years ago • 9 comments

I'm trying to get an example of an arrow in a list view. I initialized the SVG plugin when the app starts up. With one of my SVG's I just see an empty block and the other gives me the following exception. The SVG that is throwing the exception is came from The Noun Project referenced in the documentation (right_arrow.svg), and I don't remember where I got the other from (chevron_right.svg).

The exception:

Java.Lang.IllegalArgumentException: width and height must be > 0

My tag looks like this:

 <svg:SvgImage Grid.Row="0" Grid.Column="1" 
                                SvgAssembly="{x:Static helpers:SvgHelper.Assembly}" 
                                SvgPath="{x:Static helpers:SvgHelper.RightArrowPath}" 
                                HeightRequest="40" WidthRequest="40" 
                                BackgroundColor="{Binding ItemBackgroundColor}" 
                                HorizontalOptions="Center" 
                                VerticalOptions="Center" />

And the SvgHelper looks like this:

public static class SvgHelper
{
    private static Assembly _Assembly;
    public static Assembly Assembly
    {
        get
        {
            if (_Assembly != null)
                return _Assembly;

            return _Assembly = typeof(SvgHelper).GetTypeInfo().Assembly;
        }
    }

    public static string ChevronRightPath { get { return "InnlightenMobile.Content.Svg.chevron_right.svg"; } }

    public static string RightArrowPath { get { return "InnlightenMobile.Content.Svg.right_arrow.svg"; } }

}

rupe120 avatar Jan 18 '17 20:01 rupe120

I think the SvgReader only understands sizes if they are in "px" - open the SVG in a text editor and check the properties on the root element

StenPetrov avatar Jan 22 '17 22:01 StenPetrov

I have the same issue, px unit is present at x and y parameter so that is not the case.

zmayac avatar Jan 27 '17 09:01 zmayac

Can you share the svg? I can take a look at the issue tonight, I'm troubleshooting the library anyway

Sent from my iPhone

On Jan 27, 2017, at 1:14 AM, zmayac [email protected] wrote:

I have the same issue, px unit is present at x and y parameter so that is not the case.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub, or mute the thread.

StenPetrov avatar Jan 27 '17 20:01 StenPetrov

zmayac avatar Jan 27 '17 20:01 zmayac

Originally x and y were set to 0px, here i changed it to 40px, no difference.

zmayac avatar Jan 27 '17 20:01 zmayac

In the SVG attached there are no width and height tags Try this:

<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"
    width="100px" height="100px"
    viewBox="0 0 16 16" enable-background="new 0 0 16 16" xml:space="preserve">

StenPetrov avatar Jan 27 '17 23:01 StenPetrov

Now i get blank image, no exception but image doesen't render.

zmayac avatar Jan 29 '17 15:01 zmayac

Any solution?

diasnicolas avatar Feb 08 '17 12:02 diasnicolas

I had this same issue. Initially i was getting the width and height must be greater than 0 error. Then i added those tags and it was resolved. Then it wasn't rendering. For me, it was because the line itself didn't have fill="color". I had gotten the svg file from Google's material icon site and they were specifying the fill in the svg tag so svg fill="#000000". i moved the fill into the path tag ( path fill="#000000" ) and it began rendering. I know this is a bit late, but hopefully it will help someone else having this problem.

johnmangold avatar Mar 09 '17 22:03 johnmangold