navigation: transfering object

Eduard Kaufmann 311 Reputation points
2023-01-24T08:12:07.8133333+00:00
Hi,
thank you for your time. Be aware:  I'm a MAUI beginner!

The final objektiv: when pressing the 'Button' in the 'MainPage' --> show the objects (images) in the 'AreaPage'.
PS: I made my test-app public: 'github.com/edikaufmann/HikeFinder'

some remarks, now:
- only the Button: VAR-Haute, Command="{Binding VARhCommand}" is (yet) potentially made to navigate to the 'AreaPage'
  using 'await Shell.Current.GoToAsync......'. See also AppShell etc. 
  (the other Buttons still use the MainPage as target)

when navigating to the new page (AreaPage); the page comes up BUT I never see the objects I intend to transfer.

- as said, the 'AreaPage' comes up but does NOT show/keep any content! BUT, when going back, the content shows in the 'MainPage'
- I  guess I screw something with the object / program logic!

thanks for taking the time

any help is appreciated
ed
Developer technologies .NET .NET MAUI
0 comments No comments
{count} votes

Accepted answer
  1. Anonymous
    2023-01-25T05:14:07.2733333+00:00

    Hello,

    when navigating to the new page (AreaPage); the page comes up BUT I never see the objects I intend to transfer.

    Please open your AreaViewModel.cs to achieve IQueryAttributable interface, then you can get data in the ApplyQueryAttributes method by query["Hikes"]. You can refer to following code.

    public partial class AreaViewModel : BaseViewModel, IQueryAttributable
    {
        public ObservableCollection<Hike> Hikes { get; } = new();
        [ObservableProperty]
        Hike hike;
        [ObservableProperty]
        bool isRefreshing;
        public void ApplyQueryAttributes(IDictionary<string, object> query)
        {
            ObservableCollection<Hike> rawList = query["Hikes"] as ObservableCollection<Hike>;
            foreach (Hike item in rawList)
            {
                Hikes.Add(item);
            }
        }
    }
    

    Please remove [QueryProperty(nameof(Hike), "Hike")] as well.

    Best Regards,

    Leon Lu


    If the answer is the right solution, please click "Accept Answer" and kindly upvote it. If you have extra questions about this answer, please click "Comment".

    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.

    1 person found this answer helpful.

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.