I am developing an application in xamarin forms and I have problems accessing the event of a button that I have in a CollectionView. For each button that is selected, depending on the row it is in, it will do a different thing with the id.
My xaml code with the CollectionView is as follows:
<CollectionView.ItemTemplate> <DataTemplate> <Grid Padding="10"> <Grid.ColumnDefinitions> <ColumnDefinition Width="10" /> <ColumnDefinition Width="120" /> <ColumnDefinition Width="100" /> <ColumnDefinition Width="250" /> <ColumnDefinition Width="85" /> <ColumnDefinition Width="70" /> <ColumnDefinition Width="70" /> </Grid.ColumnDefinitions> <Label Grid.Column="1" Text="{Binding id_cliente}" TextColor="black" VerticalOptions="CenterAndExpand" FontAttributes="Bold" /> <Label Grid.Column="2" Text="{Binding categoria}" FontAttributes="Italic" VerticalOptions="CenterAndExpand" TextColor="black"/> <Label Grid.Column="3" Text="{Binding descripcion}" TextColor="black" VerticalOptions="CenterAndExpand" FontAttributes="Bold" /> <Label Grid.Column="4" Text="{Binding estado}" TextColor="Yellow" VerticalOptions="CenterAndExpand" FontAttributes="Bold" /> <Button Grid.Column="5" Text="Confirmar" BorderColor="#2b3c3c" BorderWidth="1" FontAttributes="Bold" BackgroundColor="#4ba862" TextColor="White" HeightRequest="60" Margin="0,0,0,0" x:Name="btnconfirmar" Clicked="ButtonConfirmacion_Clicked" Command="{Binding id_trabajo}"/> <Button Grid.Column="6" Text="Asignar" BorderColor="#2b3c3c" BorderWidth="1" FontAttributes="Bold" BackgroundColor="#4ba862" TextColor="White" HeightRequest="60" Margin="0,0,0,0" x:Name="btnasignar" Clicked="ButtonListaTrabajos_Clicked"/> </Grid> </DataTemplate> </CollectionView.ItemTemplate> </CollectionView> And in the cs code of that page I have:
private void ButtonConfirmacion_Clicked(object sender, EventArgs e) { Trabajo selectedItem1 = e.CurrentSelection[0] as Trabajo; } This code, when that row is selected, with an OnSelectionChanged (sender, e) method if it picks up the item which has been selected.
https://stackoverflow.com/questions/67223880/collect-the-identifier-of-a-button-in-a-row-of-a-collectionview-in-xamarin-forms April 23, 2021 at 12:06PM
没有评论:
发表评论