简体   繁体   中英

Display a page with extended information

I have the following functionality given below: 在此处输入图片说明

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, eg 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?

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>

use the Label 's 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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM