I have the following ListView which displays a button for each item in the list. I want the buttons to pass through their primary key 'BoxID' when clicked and open up a new page. The problem arises due to the corresponding cs document not being able to reference the button. Why is the cs function not able to access this button? Is there a way around this?
XAML:
<ListView x:Name="boxList" ItemsSource="{Binding Boxes}">
<ListView.ItemTemplate>
<DataTemplate>
<ViewCell>
<ViewCell.View>
<StackLayout Orientation="Horizontal" Padding="10,0">
<StackLayout HorizontalOptions="StartAndExpand">
<Button x:Name="editBoxButton" Text="{Binding
BoxName}" CommandParameter="{Binding
BoxID}"
FontAttributes="Bold" Clicked="editBox"
HeightRequest="75" WidthRequest="150"
FontSize="Medium" BorderColor="Black"/>
</StackLayout>
<Label HorizontalOptions="EndAndExpand"
VerticalOptions="Center" Text="{Binding Complete}"/>
</StackLayout>
</ViewCell.View>
</ViewCell>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
CS:
private void editBox(object sender, EventArgs e) {
int temp_boxID = editBoxButton.CommandParameter;
Navigation.PushModalAsync(new EditBoxPage(temp_boxID));
}
Thanks