I'm trying to create a button with the Command
event inside a ListView in MVVM
, but it's not falling on the event in ViewModel
.
How can I make this button Command
access your method in ViewModel
?
And also, how do I get the value of Label
"lblCEP" in this event Command
to be able to move 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;
}
});