.NET MAUI – Forget Me Not – Part 5

Building on the previous blog posts, here I’d like to illustrate how you can pass complex data from one page’s view model to another’s.

Let’s assume we’ve tapped on the Buddies Icon on the tab bar and were taken to the BuddyList:

If we tap on one of our buddies, in this case, Rodrigo, we should be taken to the details page for that buddy. We could pass along the buddy’s id, or we can pass the buddy object itself.

To pass the entire Buddy object, we will create a dictionary that will contain an identifying text as the key, and the SelectedBuddy as the value,

var navigationParameter = new Dictionary<string, object>
{
    {"SelectedBuddy", SelectedBuddy}
};

We can now pass that along to the details page using Shell navigation.

await Shell.Current.GoToAsync($"buddydetail", navigationParameter);

“buddydetail” is the name you gave the BuddyDetails page in the constructor in AppShell.xaml.cs

public AppShell()
{
     InitializeComponent();

     Routing.RegisterRoute("buddydetail", typeof(BuddyDetail));

This routing matches the key “buddydetail” to the BuddyDetail page. Returning to the Shell navigation above, we see navigationParameter is the second param for the GoToAsync call. That is, we pass along the dictionary that contains our object. (We can pass as many objects as we like, each as an entry in the dictionary).

Receiving the data

In the view model for the details page, BuddyDetailViewModel, we use the QueryProperty attribute to indicate the name of the property to assign the passed-in object to and the key in the dictionary associated with that object.

Looking a few paragraphs up we can see that the dictionary has an entry with the key “SelectedBuddy” which has a value of the SelectedBuddy object. Here we are going to retrieve that into a local property, also named SelectedBuddy

[ObservableObject]
[QueryProperty(nameof(SelectedBuddy), "SelectedBuddy")]
public partial class BuddyDetailViewModel

Let me review that briefly as it can get confusing. There is the name of the local property: SelectedBuddy. There is the first parameter in the QueryProperty attribute: nameof(SelectedBuddy). These are 1:1 — the nameof is pointing to a property in this (receiving) class. Finally, there is the second param in the attribute, the string “SelectedBuddy” which is the key into the dictionary whose value will be assigned to the SelectedBuddy property. Right? Piece of pie.

We want to bind to a number of the properties of the buddy we just passed in. First, we’ll create those properties:

[ObservableProperty] private string name;
[ObservableProperty] private string emailAddress;
[ObservableProperty] private string code;
[ObservableProperty] private string? phoneNumber;
[ObservableProperty] private InvitationStatus status;
[ObservableProperty] private DateTime buddySince;
[ObservableProperty] private string buddySinceString;
[ObservableProperty] private string mailingAddressLine1;
[ObservableProperty] private string mailingAddressLine2;
[ObservableProperty] private int id;

Now all we need to do is set those properties using the object that was passed in and assigned to our SelectedBuddy property

 private Buddy selectedBuddy;
 public Buddy SelectedBuddy
 {
     get => selectedBuddy;
     set
     {
         SetProperty(ref selectedBuddy, value);
         Name = value.Name;
         EmailAddress = value.EmailAddress;
         PhoneNumber = value.PhoneNumber;
         Status = value.Status;
         BuddySince = value.BuddySince;
         BuddySinceString = BuddySince.ToString("D");
         MailingAddressLine1 = value.MailingAddressLine1;
         MailingAddressLine2 = value.MailingAddressLine2;
         Id = value.Id;
     }
 }

We can now display the details of the selected buddy using data binding. in the XAML.

Notice that there are two buttons: one to see the occasions you’ve asked to be reminded about, with regard to this buddy (e.g., the buddy’s birthday). The second button will display the buddy’s preferences. Each of these is made easier by using a service, in this case BuddyService. But how do we access the methods in BuddyService? This will be the topic of the next blog entry: Dependency Injection in MAUI.

Unknown's avatar

About Jesse Liberty

** Note ** Jesse is currently looking for a new position. You can learn more about him at https://jesseliberty.bio Thank you. Jesse Liberty has three decades of experience writing and delivering software projects and is the author of 2 dozen books and a couple dozen online courses. His latest book, Building APIs with .NET, is now available wherever you buy your books. Liberty was a Team Lead and Senior Software Engineer for various corporations, a Senior Technical Evangelist for Microsoft, a Distinguished Software Engineer for AT&T, a VP for Information Services for Citibank and a Software Architect for PBS. He is a 13 year Microsoft MVP.
This entry was posted in Essentials and tagged , , . Bookmark the permalink.

869 Responses to .NET MAUI – Forget Me Not – Part 5

  1. LhanepiliA's avatar LhanepiliA says:

    What a material of un-ambiguity and preserveness of valuable know-how regarding unpredicted feelings.
    บาคาร่า

  2. 주소월드's avatar 주소월드 says:

    This platform exceeded my expectations with clear transparency and accurate charts.

  3. depobos's avatar depobos says:

    I’ve been active for a few days, mostly for using the API, and it’s always useful analytics. I moved funds across chains without a problem.

  4. depobos's avatar depobos says:

    This platform exceeded my expectations with great support and seamless withdrawals. I moved funds across chains without a problem.

  5. Michaelpoick's avatar Michaelpoick says:

    These products – strongest thc cream for pain enlarge on a excite happily in the interest of conflicting preferences and routines. The THCA flower feels like a more traditional superior, the THCA vape pen is gargantuan in the course of convenience, and the THC cream is lenient to cover in a basic self-care routine. The textures, packaging, and all-inclusive image are solid. Each product feels conforming, easy to use, and thoughtfully made.

  6. Craiggairm's avatar Craiggairm says:

    Secure you heard of mood delta 9 gummies THCA flower? This is uncovered cannabis in its unconstrained state, overflowing with tetrahydrocannabinolic acid. In its hyperborean manner, THCA won’t pick up you high. But in olden days you apply animate—like smoking, vaporizing, or baking—it converts into deathless, potent THC. It offers a legal, forward, and in full natural custom to exposure the apparatus’s buxom budding faithfully as personality intended.

  7. situstoto's avatar situstoto says:

    Wow! This is a cool platform. They really do have the wide token selection. My withdrawals were always smooth.

  8. depobos's avatar depobos says:

    I’m impressed by the robust security. I’ll definitely continue using it. The updates are frequent and clear.

  9. 주소월드's avatar 주소월드 says:

    I’ve been using it for a year for cross-chain transfers, and the great support stands out.

  10. 주소모음's avatar 주소모음 says:

    Wow! This is a cool platform. They really do have the responsive team.

  11. Interesting to see how on-chain liquidity is improving with Blaze Swap.

  12. BrandonHoomb's avatar BrandonHoomb says:

    Грамотный подбор офисной обстановки напрямую влияет на самочувствие и продуктивность сотрудников.
    Важнейший фактор — это эргономичность cтульев и столов.
    Добротная корпусная мебель способна снижать усталость и предотвращать заболевания позвоночника.
    Точно так же важен внешний облик предметов, ведь он создаёт имидж фирмы для партнёров и посетителей.
    https://mindful.worldsfashion.ru/redirect.php?id=4n7IETCO
    Стоит присматриваться на материалы: массив, качественный стальной каркас и экологичные пропитки.
    Практичность мебели проявляется в организации ящиков и регулировок под индивидуальные нужды.
    Бюджет также имеет значение, но скупость на этих изделиях может обернуться скрытым издержкам на лечение или замену.
    Поэтому, выбирайте проверенных производителей с официальными обязательствами и сертификатами.

  13. Interesting to see how on-chain liquidity is improving with Blaze Swap.

  14. Fiatogel's avatar Fiatogel says:

    I’ve been using it for a year for swapping tokens, and the quick deposits stands out.

  15. Fiatogel's avatar Fiatogel says:

    I was skeptical, but after a week of fiat on-ramp, the quick deposits convinced me.

  16. LhanepiliA's avatar LhanepiliA says:

    Hello it’s me, I am also visiting this web page on a regular basis, this web site is really fastidious and the users are truly sharing pleasant thoughts.
    buy cannabis online for xxx adult porn video

  17. Merchant Moe feels less like a basic swap platform and more like real Mantle DeFi infrastructure, especially in this analysis: merchant moe.

  18. kinetiq user's avatar kinetiq user says:

    I’ve been exploring liquid staking lately and kinetiq looks like a strong solution for capital efficiency.

  19. IsmaelNiz's avatar IsmaelNiz says:

    Hi to every body, it’s my first go to see of this web site; this webpage carries awesome and actually excellent information in support of visitors.
    Watch sexual porno video xxx sex adults site

  20. Your article helped me a lot, is there any more related content? Thanks! https://accounts.binance.com/register/person?ref=IXBIAFVY

  21. Tarnardcrive's avatar Tarnardcrive says:

    Please let me know if you’re looking for a article author for your weblog. You have some really great articles and I feel I would be a good asset. If you ever want to take some of the load off, I’d really like to write some material for your blog in exchange for a link back to mine. Please shoot me an email if interested. Thank you!
    Hot to Burn Multiplier

  22. Interesting how DeFi is shifting toward sustainability, especially with infinite capital frameworks becoming more relevant.

  23. Ismencrive's avatar Ismencrive says:

    This is really interesting, You are a very skilled blogger. I have joined your rss feed and look forward to seeking more of your magnificent post. Also, I have shared your site in my social networks!
    tada gaming

  24. kinetiq pro's avatar kinetiq pro says:

    I like how users can stay liquid while earning yield with kinetiq.

  25. EarnestCor's avatar EarnestCor says:

    Heya! I know this is kind of off-topic but I needed to ask. Does managing a well-established website such as yours require a lot of work? I am brand new to operating a blog but I do write in my diary on a daily basis. I’d like to start a blog so I can easily share my personal experience and feelings online. Please let me know if you have any kind of suggestions or tips for new aspiring blog owners. Thankyou!
    free spins no deposit

  26. I personally find that wow! This is a cool platform. They really do have the robust security. The updates are frequent and clear.

  27. I personally find that i value the robust security and wide token selection. This site is reliable. My withdrawals were always smooth.

  28. I personally find that chris here — I’ve tried using the bridge and the scalable features impressed me.

  29. I’ve been exploring DeFi yield platforms lately and rhea finance looks like a strong contender.

  30. This gives a clearer view of DeFi infrastructure, especially with thor swap in focus.

  31. I don’t think the title of your article matches the content lol. Just kidding, mainly because I had some doubts after reading the article. https://accounts.binance.info/register/person?ref=IHJUI7TF

  32. I like how bonding mechanics are explained through olympusdao finance.

  33. Feels like DeFi is evolving into full monetary systems, and Olympus DAO reflects that shift.

  34. Feels like liquidity is becoming an owned asset, and Olympus DAO highlights that.

  35. I’ve been using it for a week for checking analytics, and the easy onboarding stands out.

  36. I’ve been exploring DeFi lending protocols and Flux Finance looks like a strong step toward real yield.

  37. tron usdt's avatar tron usdt says:

    I’ve been using it for a few days for using the bridge, and the clear transparency stands out.

  38. This CBD lubricator stands not on because of its smooth-spoken consistency and balanced taste. The bottle motif is smarmy and applicable, and the dropper works on the nail without dripping. It feels like a well-crafted yield made with prominence to factor, from labeling to packaging.

  39. I personally find that i value the low fees and reliable uptime. This site is reliable.

Leave a Reply

Your email address will not be published. Required fields are marked *