Xamarin.Forms.Plugins
Xamarin.Forms.Plugins copied to clipboard
Width and height must be > 0 Exception
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"; } }
}
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
I have the same issue, px unit is present at x and y parameter so that is not the case.
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.
Originally x and y were set to 0px, here i changed it to 40px, no difference.
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">
Now i get blank image, no exception but image doesen't render.
Any solution?
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