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
close icon

[All platforms] ImageSource not rendering if initialized by code

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

1 Reply

HM Hemalatha Marikumar Syncfusion Team 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. 
 


Loader.
Live Chat Icon For mobile
Up arrow icon