3
I’m trying to create a button with the event Command within a Listview on MVVM, but is not falling in the event ViewModel.
How do I get this button Command access your method on ViewModel ?
And also, how do I take the value of Label "lblCEP" at this event Command to be able to switch to another view ?
My code:
/// XAML
<ListView x:Name="lvEnderecos" RowHeight="205">
    <ListView.ItemTemplate>
      <DataTemplate>
        <ViewCell>
            <Label x:Name="lblCEP" Font="14" TextColor="Black" Text="{Binding CliEndCep, StringFormat='CEP: {0}'}"></Label>
              <Grid x:Name="GridControl3" RowSpacing="0" ColumnSpacing="0">
                <Grid.RowDefinitions>
                  <RowDefinition Height="25"/>
                </Grid.RowDefinitions>
                <Grid.ColumnDefinitions>
                  <ColumnDefinition Width="Auto" />
                  <ColumnDefinition Width="Auto" />
                </Grid.ColumnDefinitions>
                <StackLayout x:Name="stkManipularEndereco" Grid.Row="0" Grid.Column="0" Padding="5, 0, 0, 0" HeightRequest="25" WidthRequest="25">
                  <Button x:Name="btnEditarEndereco" BackgroundColor="Transparent" Image="editar2.png" HeightRequest="25" WidthRequest="25" Command="{Binding EditarEnderecoCommand}" />
                </StackLayout>
              </Grid>
            </StackLayout>
        </ViewCell>
      </DataTemplate>
    </ListView.ItemTemplate>
  </ListView>
/// Viewmodel
public ICommand EditarEnderecoCommand { get; protected set; }
        this.EditarEnderecoCommand = new Command(async () =>
        {
           try
           {
                await page.DisplayAlert("Alerta", "Você clicou aqui :)", "OK");
           }
           catch (Exception ex)
           {
                throw ex;
           }
       });
						
i made the button call on Behind code and it worked. I’ll do it there anyway, but I put the zip code Binding in the button Commandparameter, but how do I get this value there in code Behind ?
– AndreeH
@Andreeh I added in reply
– rubStackOverflow