0
我有以下ListView显示列表中每个项目的按钮。我想让按钮在点击时通过主键'BoxID'并打开一个新页面。问题出现是由于相应的cs文档无法引用按钮。为什么cs功能无法访问此按钮?有没有解决的办法?XAML如何访问ListView中的Button?
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));
}
感谢
检查出来https://stackoverflow.com/questions/25912091/how-do-i-pass-the-button-as-commandparameter-from-xaml-in-a-xamarin-forms-page –