Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Please give me some explaination about the following Microsoft.ToolKit.MVVM

Please give me some explaination about the following Microsoft.ToolKit.MVVM

Scheduled Pinned Locked Moved C#
tutorialwpfcomarchitecturequestion
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • C Offline
    C Offline
    Code4Ever
    wrote on last edited by
    #1

    I want to learn about the Messenger feature of Microsoft.ToolKit.MVVM. In the documentation, I found the following code:

    // Create a message
    public class LoggedInUserRequestMessage : RequestMessage
    {
    }

    // Register the receiver in a module
    WeakReferenceMessenger.Default.Register(this, (r, m) =>
    {
    // Assume that "CurrentUser" is a private member in our viewmodel.
    // As before, we're accessing it through the recipient passed as
    // input to the handler, to avoid capturing "this" in the delegate.
    m.Reply(r.CurrentUser);
    });

    // Request the value from another module
    User user = WeakReferenceMessenger.Default.Send();

    I don't know what this, r, and m are. Do we need to always inherit from RequestMessage? I need a simple example of how to use the Messenger feature. Please guide me.

    OriginalGriffO 1 Reply Last reply
    0
    • C Code4Ever

      I want to learn about the Messenger feature of Microsoft.ToolKit.MVVM. In the documentation, I found the following code:

      // Create a message
      public class LoggedInUserRequestMessage : RequestMessage
      {
      }

      // Register the receiver in a module
      WeakReferenceMessenger.Default.Register(this, (r, m) =>
      {
      // Assume that "CurrentUser" is a private member in our viewmodel.
      // As before, we're accessing it through the recipient passed as
      // input to the handler, to avoid capturing "this" in the delegate.
      m.Reply(r.CurrentUser);
      });

      // Request the value from another module
      User user = WeakReferenceMessenger.Default.Send();

      I don't know what this, r, and m are. Do we need to always inherit from RequestMessage? I need a simple example of how to use the Messenger feature. Please guide me.

      OriginalGriffO Offline
      OriginalGriffO Offline
      OriginalGriff
      wrote on last edited by
      #2

      this is a keyword in C# which always represents the current instance of the current class - as such it s only ever available in non-static methods, because static code does not and cannot refer to an instance at all. It's like a car: "my car" is an instance, "your car" is a different instance. But "this car" could refer to either, and the question "what colour is this car?" will return a different value depending on which instance we are talking about. If we are driving in my car, then the answer would be "black" because "my car" is a black Mercedes. If your BMW is being driven then the answer might be "green".r r and m are parameters which come from the invocation of the lambda: MVVM - The MVVM Light Messenger In-Depth | Microsoft Docs[^] is a good place to start.

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt AntiTwitter: @DalekDave is now a follower!

      "I have no idea what I did, but I'm taking full credit for it." - ThisOldTony
      "Common sense is so rare these days, it should be classified as a super power" - Random T-shirt

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups