Please guide me with an example as in how to use this binding imagesource. I am trying to a create a custom control with image and a label.
Hi, @AjayKumarKR
public class MyEntity { public string ImageSource {get;set;} public string LabelText {get;set;} }
In your XAML.CS page you set your BindingContext like : public partial class YOUR_PAGE : ContentPage { public YOUR_PAGE() { InitializeComponent(); MyEntity myEntity=new MyEntity() { ImageSource="your_image.png"; //for example LabelText="your label text here"; }; BindingContext = myEntity; }
in your XAML page, use binding like :<Label Text="{Binding LabelText}" /> <Image Source="{Binding ImageSource}" />
Hope that helps
Mabrouk.
Answers
Hi, @AjayKumarKR
public class MyEntity { public string ImageSource {get;set;} public string LabelText {get;set;} }
In your XAML.CS page you set your BindingContext like :
public partial class YOUR_PAGE : ContentPage { public YOUR_PAGE() { InitializeComponent(); MyEntity myEntity=new MyEntity() { ImageSource="your_image.png"; //for example LabelText="your label text here"; }; BindingContext = myEntity; }
in your XAML page, use binding like :
<Label Text="{Binding LabelText}" /> <Image Source="{Binding ImageSource}" />
Hope that helps
Mabrouk.
This works fine. But I am unable to figure out how to reference different images when creating different instances of the custom control.
The example which i referred to was unclear. Could you please help with that and explain the related concepts?
The example which I referred to is :
http://blog.falafel.com/creating-reusable-xaml-user-controls-xamarin-forms/
Please explain me the bindings in this code.