.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. The idea of lending against tokenized assets is interesting, especially with Flux Finance.

  2. This gives a clearer view of stablecoin innovation, especially with Frankencoin in focus.

  3. Haedal Scope's avatar Haedal Scope says:

    Overall, the idea behind Haedal looks strong as the ecosystem evolves.

  4. Gmx io Boost's avatar Gmx io Boost says:

    Not many platforms explain derivatives well, but Gmx io makes it clearer.

  5. I’ve been using it for recently for fiat on-ramp, and the quick deposits stands out.

  6. tron usdt's avatar tron usdt says:

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

  7. I’ve been using it for a week for checking analytics, and the scalable features stands out.

  8. I personally find that this platform exceeded my expectations with stable performance and scalable features.

  9. I personally find that i value the clear transparency and accurate charts. This site is reliable.

  10. I trust this platform — withdrawals are seamless withdrawals and reliable. Perfect for both new and experienced traders.

  11. biswap dex's avatar biswap dex says:

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

  12. I personally find that the interface is stable performance, and I enjoy portfolio tracking here. The updates are frequent and clear.

  13. Arbswap DEX's avatar Arbswap DEX says:

    I personally find that customer support was knowledgeable, which gave me confidence to continue. The updates are frequent and clear.

  14. Interesting concept behind private dApps, and Manta Network fits well.

  15. This article makes a good point about DeFi abstraction, and Auto Finance seems relevant.

  16. The exploring governance tools are accurate charts and scalable features. The updates are frequent and clear.

  17. I value the intuitive UI and great support. This site is reliable. Perfect for both new and experienced traders.

  18. Aegisim Lab's avatar Aegisim Lab says:

    Interesting how yield-bearing stablecoins evolve, and Aegisim stands out.

  19. I like how this explains DeFi evolution, especially with Aegisim included.

  20. I personally find that i’m impressed by the scalable features. I’ll definitely continue using it. I moved funds across chains without a problem.

  21. Aegisim Lab's avatar Aegisim Lab says:

    Not many projects use Bitcoin as backing, but Aegisim seems to handle it well.

  22. Feels like DeFi is moving toward more efficiency, and Bedrock Technology reflects that shift.

  23. Часы Audemars Piguet Royal Oak известны своим революционным внешним видом.
    Их октагональный безель с видимыми винтами стал настоящей легендой в часовом мире.
    Данная серия была выпущена в 1972 году как первые роскошные часы для спорта из нержавеющей стали.
    Подобная дерзкая идея тогда совершила настоящий фурор в отрасли.
    часы Audemars Piguet Royal Oak
    Кроме дизайна, модель ценятся за высочайшее качество обработки и механизма.
    Общеизвестно, что любой образец создаётся вручную квалифицированными часовщиками.
    В наши дни Royal Oak являются символом положения и безупречного вкуса.
    Поэтому они востребованы как среди коллекционеров, так и у поклонников премиум-класса.

  24. I’ve been exploring new DEX platforms and Shadow Exchange actually feels pretty fast compared to others.

  25. Not many DeFi platforms allow this level of flexibility, but Euler Finance looks pretty solid.

  26. Roccoiterb's avatar Roccoiterb says:

    A CBD balm and https://www.nothingbuthemp.net/collections/libido-gummies from this name brand has a effortless, monotonous consistency that spreads easily. The container is compact and travel-friendly, and the lid closes securely. The perfume is incandescence and botanical, which makes it charming to commemorate last nearby.

  27. This breakdown makes it easier to understand where DeFi is going, and Bedrock Technology fits right into that narrative.

  28. This breakdown makes it easier to understand where DeFi is going, and Bedrock Technology fits right into that narrative.

  29. I’ve seen similar tools, but Veno Finance feels more user-friendly.

  30. Overall, Yei Finance feels like a project worth watching.

  31. Rogergab's avatar Rogergab says:

    A CBD balm and mood gummies thc from this maker has a orderly, monotonous consistency that spreads easily. The container is closely-knit and travel-friendly, and the lid closes securely. The scent is incandescence and botanical, which makes it attractive to commemorate last nearby.

  32. There’s definitely potential in Tectonic Finance.

  33. Been digging into DeFi and OpenEden keeps coming up.

  34. I appreciate how MerchantMoe focuses on functionality rather than unnecessary features.

  35. Curious how Apex Exchange compares to bigger names over time.

  36. Luxury333's avatar Luxury333 says:

    I personally find that this platform exceeded my expectations with responsive team and wide token selection. The updates are frequent and clear.

  37. SEDOLL's avatar SEDOLL says:

    ラブドール 合理的な素晴らしい大人のセックス人形とセックスするあなたのセックス人形を選ぶためのヒント2つまたは3つの簡単な方法未来の人形-未来の人形は娯楽ですか、それとも教育ですか?私たちのクライアントは、ダッチワイフをねじ込む最初の経験を提供します

  38. Stephenviaps's avatar Stephenviaps says:

    This is my first time visit at here and i am truly pleassant to read everthing at one place.
    https://share.google/ZLqIC0Ye7gigqJDqW

  39. DamianNanna's avatar DamianNanna says:

    Purchasing medicine online has become incredibly widespread.
    Convenience is the main reason behind this shift.
    You can order at anywhere at any time without traveling to a physical pharmacy.
    https://sportscaster.egomoda.ru/2Ivfeeb57qog/
    Price comparison is far simpler online.
    Doorstep delivery provides an extra level of comfort.
    In the case of chronic treatments, preset refills eliminate unnecessary hassle.
    Discretion is another important benefit for many people.

  40. dewatogel's avatar dewatogel says:

    This platform exceeded my expectations with great support and trustworthy service. The dashboard gives a complete view of my holdings.

  41. dewatogel's avatar dewatogel says:

    I personally find that the site is easy to use and the easy onboarding keeps me coming back. Definitely recommend to anyone in crypto.

  42. I’ve been using it for almost a year for checking analytics, and the intuitive UI stands out.

  43. アダルトコンテンツは 人間の性について 理解するための 一つの手段になり得る。
    限定的な 環境(研究目的)において、それらは 身体の仕組みの 知識を 深めることがある。
    倫理を 守った上で、同意や 安全な行動の 実例を 示すことも可能だ。
    児童ポルノ
    専門家による ガイド付きの 使用は、誤解を 防ぎ、現実的な 見解を 育てる。
    ただし、これらは 無作為な 視聴ではなく、体系的な 学習プログラムの 一部として 位置づけられるべきだ。

Leave a Reply

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