We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

is it possible to use svg images for sfButton?

Thread ID:





148753 Nov 1,2019 11:59 PM UTC Nov 4,2019 09:17 AM UTC Xamarin.Forms 1
Tags: SfButton
Asked On November 1, 2019 11:59 PM UTC

xamarin.forms button support svg images using like ffimageloadingsvg now using xamarin.forms 4.x version. Does SfButton support using svg? is there any plan for it? 

Hemalatha Marikumar [Syncfusion]
Replied On November 4, 2019 09:17 AM UTC

Hi Emil, 
Greetings from Syncfusion. 
Query: Does SfButton support using svg? 
Yes, SfButton supports svg image format using its Content property, which is used to load a custom view. With the help of SkiaSharp, we can draw the SVG path and make it as View by using SKCanvasView as per in below code snippet. 
Code snippet [XAML]: 
<buttons:SfButton > 
        <Grid BackgroundColor="#ff5500"> 
                <ColumnDefinition Width="50"/> 
                <ColumnDefinition Width="*"/> 
            <local:Icon /> 
            <Label Text="Connect with Strava" 
                   TextColor = "#ffffff"/> 
Code snippet[C#]: 
public class Icon : Frame 
    private readonly SKCanvasView canvasView = new SKCanvasView(); 
    public Icon() 
        Padding = new Thickness(0); 
        BackgroundColor = Color.Transparent; 
        HasShadow = false; 
        Content = canvasView; 
        canvasView.PaintSurface += CanvasViewOnPaintSurface; 
    private void CanvasViewOnPaintSurface(object sender, SKPaintSurfaceEventArgs args) 
        SKCanvas canvas = args.Surface.Canvas; 
        if (string.IsNullOrEmpty("SimpleSample.level2.svg")) 
        using (Stream stream = GetType().Assembly.GetManifestResourceStream("SimpleSample.level2.svg")) 
            SKSvg svg = new SKSvg(); 
            SKImageInfo info = args.Info; 
            canvas.Translate(info.Width / 2f, info.Height / 2f); 
            SKRect bounds = svg.ViewBox; 
            float xRatio = info.Width / bounds.Width; 
            float yRatio = info.Height / bounds.Height; 
            float ratio = Math.Min(xRatio, yRatio); 
            canvas.Translate(-bounds.MidX, -bounds.MidY); 
Please download the sample from the below link. 
Please get back to us if you need any further assistance on this. 
Hemalatha M. 


This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Please sign in to access our forum

This page will automatically be redirected to the sign-in page in 10 seconds.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

Live Chat Icon For mobile
Live Chat Icon