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. (Last updated on: June 24, 2019).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

[All platforms] ImageSource not rendering if initialized by code

Thread ID:

Created:

Updated:

Platform:

Replies:

150799 Jan 20,2020 02:00 PM UTC Jan 21,2020 06:00 PM UTC Xamarin.Forms 1
loading
Tags: SfButton
Marco Negroni
Asked On January 20, 2020 02:00 PM UTC

Good morning,
in our app we have few generated by code SfButtons, if we set the IconSource by code the icon will not be displayed:

SfButton selectDatabaseSfButton = new SfButton();
selectDatabaseSfButton.CornerRadius = 5d;
selectDatabaseSfButton.HeightRequest = 40d;
selectDatabaseSfButton.BackgroundColor = Color.FromHex("#007bff");
selectDatabaseSfButton.Margin = new Thickness(0d, 0d, 10d, 0d);
selectDatabaseSfButton.ImageSource = ImageSource.FromResource("buttonIcon_glyphicons_528_database.png");
selectDatabaseSfButton.ShowIcon = true;
selectDatabaseSfButton.CommandParameter = databaseDBData.Name;
selectDatabaseSfButton.Clicked += SelectDatabaseSfButton_Clicked;
selectDatabaseSfButton.Text = Sendra2Resources.BUTTON_SELECTDATABASEVIEW_SELECTDATABASE;

Thanks in advance

Hemalatha Marikumar [Syncfusion]
Replied On January 21, 2020 06:00 PM UTC

Hi Marco Negroni, 
 
Greetings from Syncfusion. 
 
We have checked the provided code snippet and if your requirement is to display Image with build action as the Embedded Resource [ Loaded in PCL instead of platform specific] as per in below screenshot then specific the ImageSource as per in below code snippet 
 
 
 
Code Snippet [C#]: QuerySample as Namespace 
public MainPage() 
        { 
            InitializeComponent(); 
            StackLayout stackLayout = new StackLayout(); 
            SfButton selectDatabaseSfButton = new SfButton(); 
            selectDatabaseSfButton.CornerRadius = 5d; 
            selectDatabaseSfButton.HeightRequest = 40d; 
            selectDatabaseSfButton.BackgroundColor = Color.FromHex("#007bff"); 
            selectDatabaseSfButton.Margin = new Thickness(0d, 0d, 10d, 0d); 
            selectDatabaseSfButton.ImageSource = ImageSource.FromResource("QuerySample.icon.png", typeof(MainPage).GetTypeInfo().Assembly); 
            selectDatabaseSfButton.ShowIcon = true; 
            selectDatabaseSfButton.Text = "Hello"; 
 
            stackLayout.Children.Add(selectDatabaseSfButton); 
            this.Content = stackLayout; 
        } 
 
 
As per the guidelines provided in Xamarin ImageSource, we have to update the ImageSource as pe in below  
 
            Var source = ImageSource.FromResource("namespace.imagename.imagename_extension", typeof(Classname).GetTypeInfo().Assembly); 
 
 
 
Please check and let us know if you have any other concern. 
 
Regards, 
Hemalatha M. 
 


CONFIRMATION

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