private ObservableCollection<bookData> bookList;
public class bookData { public int s_number { get; set; } public string title { get; set; } public int price { get; set; } public int inventory { get; set; } public string genre { get; set; } public string explanation { get; set; } public ImageSource image { get; set; } }
grid.Children.Add(new Frame { BackgroundColor = Xamarin.Forms.Color.White, Padding = 5, HasShadow = false, Content = new Image { Source = /*ImageSource*/, Aspect = Aspect.AspectFill, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, HeightRequest = 80, } });
I want bind ImageSource in 'new Image' use C# code. I'm going to use 'image' in 'bookList' to ImageSource. How can i do that?
I want bind ImageSource in 'new Image' use C# code.
To set binding programmatically, try using the SetBinding
method for the Image
. Check the code:
Image img = new Image { Aspect = Aspect.AspectFill, HorizontalOptions = LayoutOptions.Center, VerticalOptions = LayoutOptions.Center, HeightRequest = 80, } img.SetBinding(Image.SourceProperty, "property_name"); grid.Children.Add(new Frame { BackgroundColor = Xamarin.Forms.Color.White, Padding = 5, HasShadow = false, Content = img });
Answers
To set binding programmatically, try using the
SetBinding
method for theImage
. Check the code:@Jarvan Thank you for your comment! that is helped me.