.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. I personally find that i value the robust security and intuitive UI. This site is reliable. Great for cross-chain swaps with minimal slippage.

  2. I’ve been active for over two years, mostly for using the mobile app, and it’s always accurate charts.

  3. The interface is clear transparency, and I enjoy cross-chain transfers here. Charts are accurate and load instantly.

  4. The best choice I made for staking. Smooth and accurate charts. Charts are accurate and load instantly.

  5. Fiatogel's avatar Fiatogel says:

    I’ve been active for a few days, mostly for exploring governance, and it’s always intuitive UI.

  6. Stephenviaps's avatar Stephenviaps says:

    Why people still use to read news papers when in this technological globe all is presented on web?
    https://try-kolduna.com.ua/nissan-sentra-vidnovlennya-far-pislya-dtp.html

  7. CharlesWhexy's avatar CharlesWhexy says:

    The aroma of this terpene commingling – granddaddy purple marijuana strain is really good and ingenuous, not too concentrated but hush unmistakable in the best way. It blends smoothly and adds a much bettor flavor profile without compelling everything else. Equanimous a close amount makes a contradistinction, which says a plight fro the quality. The packaging was solid, shipping was fast, and the mainly experience felt reliable. Really solid product and a certain I’d joyfully disposal again.

  8. I personally find that customer support was knowledgeable, which gave me confidence to continue. I moved funds across chains without a problem.

  9. JamesMic's avatar JamesMic says:

    The atmosphere of this terpene shade – strawberry kiwi vape juice is at bottom clean and natural, not too tireless but hush noticeable in the superlative way. It blends smoothly and adds a much better flavor chart without compelling everything else. Flush a small amount makes a contradistinction, which says a loads about the quality. The packaging was solid, shipping was rakish, and the whole happening felt reliable. Unquestionably sound produce and everyone I’d joyfully order again.

  10. I personally find that the swapping tokens process is simple and the reliable uptime makes it even better. Charts are accurate and load instantly.

  11. I was skeptical, but after a week of using the API, the reliable uptime convinced me. The mobile app makes daily use simple.

  12. Charlie here — I’ve tried exploring governance and the reliable uptime impressed me. Perfect for both new and experienced traders.

  13. Azzahrah Putri Rent Car adalah perusahaan rental mobil makassar yang berkomitmen memberikan pengalaman sewa mobil makassar terbaik, memenuhi semua kebutuhan perjalanan Anda dengan layanan yang berkualitas dan profesional. Fokus kami adalah memastikan kenyamanan dan kepuasan pelanggan, menjadikan kami mitra perjalanan yang dapat diandalkan.

  14. The best choice I made for exploring governance. Smooth and reliable uptime. My withdrawals were always smooth.

  15. I’ve been using it for a week for cross-chain transfers, and the responsive team stands out. I moved funds across chains without a problem.

  16. Bardzo ciekawy blog, rzeczowy i wyważony. Od dzisiaj zaglądam regularnie i subskrybuję kanał RSS. Pozdrowienia 🙂

  17. The interface is seamless withdrawals, and I enjoy swapping tokens here. My withdrawals were always smooth.

  18. click here's avatar click here says:

    Customer support was responsive, which gave me confidence to continue. I moved funds across chains without a problem.

  19. I personally find that fast onboarding, responsive team, and a team that actually cares. Great for cross-chain swaps with minimal slippage.

  20. ShanepiliA's avatar ShanepiliA says:

    That is very interesting, You are an overly skilled blogger. I have joined your rss feed and look forward to in the hunt for extra of your magnificent post. Also, I’ve shared your site in my social networks
    https://teletype.in/@avtobloggerua/D36QcnKeQ2k

  21. Rodneyimpah's avatar Rodneyimpah says:

    This thca flower free shipping stood thoroughly accurate away. The smell was refreshed as in the end as the gall opened, and the buds had a illustrious look with a nice texture and color. The flavor was fulgorous, crisp, and much smoother than expected, which made the whole go through more enjoyable. It felt like the amicable of pick that fits by nature into the daytime, especially when looking on something lighter in all-embracing vibe. The packaging also looked trim and gifted, which added to the appeal.

  22. I personally find that the using the bridge process is simple and the seamless withdrawals makes it even better.

  23. Fast onboarding, accurate charts, and a team that actually cares. Support solved my issue in minutes.

  24. The using the mobile app tools are quick deposits and seamless withdrawals.

  25. LewisGor's avatar LewisGor says:

    What’s up, after reading this amazing paragraph i am too glad to share my know-how here with friends.
    Watch sexual porno video xxx sex adults site

  26. EarnestCor's avatar EarnestCor says:

    What’s up i am kavin, its my first time to commenting anywhere, when i read this article i thought i could also make comment due to this sensible article.
    Watch sexual porno video xxx sex adults site

  27. Reese here — I’ve tried staking and the useful analytics impressed me.

  28. mood gummies's avatar mood gummies says:

    The CBD amassment – mood gummies offers a assortment of formats that make appropriate other preferences, and each a certain feels ok executed. The unguent appears clean and accordance, the packaging materials bear durable, and the fashion is simple till elegant. The products are comfortable to assemble and go with, thanks to obvious lids and thick sizing. Entire, the maker delivers a outstanding and carefully crafted sample without surplus extras.

  29. I personally find that this platform exceeded my expectations with stable performance and reliable uptime.

  30. I personally find that i trust this platform — withdrawals are stable performance and reliable. Definitely recommend to anyone in crypto.

  31. Timsothybioli's avatar Timsothybioli says:

    Hi there, I want to subscribe for this webpage to get most up-to-date updates, therefore where can i do it please assist.
    https://mostbet-zerkaloonline.buzz/book-of-dead-playn-go-bookofdead-slot-2/

  32. The interface is trustworthy service, and I enjoy swapping tokens here.

  33. I was skeptical, but after a few days of checking analytics, the easy onboarding convinced me.

  34. I’ve been active for almost a year, mostly for using the mobile app, and it’s always responsive team.

  35. I switched from another service because of the low fees and robust security.

  36. I personally find that the best choice I made for using the bridge. Smooth and quick deposits.

  37. Hunter here — I’ve tried testing new tokens and the scalable features impressed me.

  38. source's avatar source says:

    I switched from another service because of the reliable uptime and quick deposits. The dashboard gives a complete view of my holdings.

  39. click here's avatar click here says:

    I was skeptical, but after half a year of cross-chain transfers, the wide token selection convinced me.

  40. I was skeptical, but after a few days of using the API, the great support convinced me.

  41. Your point of view caught my eye and was very interesting. Thanks. I have a question for you. https://www.binance.info/tr/register?ref=MST5ZREF

  42. uniswap web3's avatar uniswap web3 says:

    I personally find that the staking process is simple and the fast transactions makes it even better. Definitely recommend to anyone in crypto.

  43. The best choice I made for using the API. Smooth and seamless withdrawals. Perfect for both new and experienced traders.

  44. I trust this platform — withdrawals are intuitive UI and reliable. Great for cross-chain swaps with minimal slippage.

Leave a Reply

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