显示带有扩展信息的页面 [英] Display a page with extended information
问题描述
我有以下功能:
单击详细信息时,我希望内容视图上显示的文本应显示在由推送异步创建的新详细信息页面上.如何发送包含内容中给出的信息的参数,例如标题、类别和描述.
When clicking on details, i want the text that is displayed on the contentview shall be displayed on the new detailspage that is created by push async. How can I send parameters containing the info given in the content, e.g. title, category and description.
我有一个点击手势识别器:
I have a tap gesture recognizer:
<Label.GestureRecognizers>
<TapGestureRecognizer Tapped="TapGestureRecognizer_Tapped"/>
</Label.GestureRecognizers>
这会导致创建一个带有代码的新页面:
That then leads to creating a new page with the code behind:
private async void TapGestureRecognizer_Tapped(object sender, EventArgs e)
{
await Navigation.PushAsync(new DetailsPage(user), true);
}
那么我应该如何绑定包含标题、描述和类别的标签以显示在点击创建的新页面中?
So how shall I bind the labels containing title, description and category to display in the new page that is created upon click?
这是标签背后的 xaml 代码:
Here's the xaml code behind the labels:
<StackLayout>
<StackLayout Orientation="Horizontal">
<BoxView Color="LightGray"
WidthRequest="90"
HeightRequest="90"
HorizontalOptions="Center"
VerticalOptions="Center"/>
<StackLayout Padding="0">
<Label x:Name="Title" Text="Title"
FontSize="22"
FontFamily="Grotesk"
TextColor="Black"
Margin="10, -2, 0, 0"
VerticalOptions="Fill" />
<Label x:Name="Category" Text="Category"
FontSize="16"
FontFamily="Grotesk"
TextColor="Gray"
Margin="10, -2, 0, 0"
VerticalOptions="Fill" />
<Label x:Name="Desc" Text="Lorem Ipsum is simply dummy text of the printing and typesetting industry. etc.etc"
Margin="10, -4, 0, 0"
FontSize="15"
FontFamily="Latow"
VerticalOptions="Start"
MaxLines="3"/>
</StackLayout>
</StackLayout>
推荐答案
使用Label
的BindingContext
private async void TapGestureRecognizer_Tapped(object sender, EventArgs e)
{
var label = (Label)sender;
// you will need to cast it to the correct type
var item = (MyClass)label.BindingContext;
// then pass it to your page
await Navigation.PushAsync(new DetailsPage(user,item), true);
}
这篇关于显示带有扩展信息的页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!