question

10918804 avatar image
0 Votes"
10918804 asked EmiratesAngels-2374 answered

Dynamic Page / View name

Hi,

I have a page code in my database which I am getting it by ListView Tapped like this:

 string page_code = (e.ItemData as MyData).page_code;
 string view_code = (e.ItemData as MyData).view_code;

and in my App I have a ContentPage and ContentView called P1000 or V1000

How can I do the PushModalAsync when I am having the name dynamic like the above?

Also how can I embed a ContentView in my ContentPage when the View name is Dynamic?


Thanks,
Jassim






dotnet-xamarin
5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

JarvanZhang-MSFT avatar image
0 Votes"
JarvanZhang-MSFT answered JarvanZhang-MSFT edited

Hello,​

Welcome to our Microsoft Q&A platform!

How can I do the PushModalAsync when I am having the name dynamic like the above?

Try to detect value of the item's data and perform the navigation. Then set BindingContext for the page with the passed model instance to populate the data for the views.

private void ListView_ItemTapped(object sender, ItemTappedEventArgs e)
{
    var model = e.Item as CustomModel;

    var content = model.Content;

    if (content == "item_3")
    {
        Navigation.PushModalAsync(new ItemDetailsPage(model));
    }
}

//itemDatailsPage
public partial class ItemDetailsPage: ContentPage
{
    public MainPage(CustomModel model)
    {
        InitializeComponent();

        BindingContext = model;//you could set data binding for the page with the passed model
    }
    ...
}


Best Regards,

Jarvan Zhang



If the response is helpful, please click "Accept Answer" and upvote it.

Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.

EmiratesAngels-2374 avatar image
0 Votes"
EmiratesAngels-2374 answered

But this will allow to pass a parameter and I want is something like this:

 string page = (e.ItemData as CategoryData).page_code;
    
 Navigation.PushModalAsync(new page);


5 |1600 characters needed characters left characters exceeded

Up to 10 attachments (including images) can be used with a maximum of 3.0 MiB each and 30.0 MiB total.