How to use Commandparameter in Xamarin.Forms?

Asked

Viewed 107 times

1

Good afternoon. I have a button that is mounted as follows:

<ImageButton 
    Source="{local:EmbeddedImage ResourceId=CreativeAutoMobile.Midia.btnfoto.png}" 
    BackgroundColor="#c3c3c3"
    WidthRequest="50"
    CornerRadius="10"
    Clicked="BtnEnviarFotos_Click"
    BindingContext="{Binding Source={x:Reference listaVistorias}, Path=BindingContext}"
    CommandParameter="{Binding Source={x:Reference item}, Path=BindingContext}">
</ImageButton>

It is working, but I need to redo it using code in C#, and I’m having doubts in the syntax of how Binding should be done and how Commandparameter should be used.

1 answer

0


In XAML

<ImageButton 
    Source="{local:EmbeddedImage ResourceId=CreativeAutoMobile.Midia.btnfoto.png}" 
    BackgroundColor="#c3c3c3"
    WidthRequest="50"
    CornerRadius="10"
    Clicked="BtnEnviarFotos_Click"
    CommandParameter="{Binding PARAMETRO}">
</ImageButton>

Class model c#

public class NOMEQUALQUER
{
  public string PARAMETRO{ get; set;}
}

View code-Behind C#

 this.BindingContext = new NOMEQUALQUER(){ PARAMETRO = "valor desejado"}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.