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. How to send property values via eventhandler ?

How to send property values via eventhandler ?

Scheduled Pinned Locked Moved C#
questiontutorial
4 Posts 2 Posters 18 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.
  • A Offline
    A Offline
    AtaChris
    wrote on last edited by
    #1

    public class Person : INotifyPropertyChanged
    {
    private string name;

    public event PropertyChangedEventHandler PropertyChanged;
    
    public string Name
    {
        get { return name; }
        set
        {
            object before = Name;
            name = value;
            OnPropertyChanged("Name", before, Name);
        }
    }
    
    void OnPropertyChanged(PropertyChangedEventArgs e, object? argvaluebefore = null, object? argnewvalue = null, \[CallerMemberName\] string argcallername = "", \[CallerLineNumber\] int argcallerline = 0)
    {
        //How can I inject argvaluebefore and argvalue here ?
    	
    	PropertyChanged?.Invoke(this, e);
    }
    

    }

    public class Master
    {

    Person \_person = new();
    
    
    public Master()
    {
    
    	\_person.PropertyChanged += MyHandler;
    
    
    }
    
    
    private void MyHandler(object? sender, PropertyChangedEventArgs e)
    {
    
    	//How do I retrieve the curent values of property Name here plus the value before ?
    
    }
    

    }

    Hello, I need to retrieve the propery values of class Person in MyHandler of Class Master. Any ideas what I should do ? Regards, Chris

    OriginalGriffO 1 Reply Last reply
    0
    • A AtaChris

      public class Person : INotifyPropertyChanged
      {
      private string name;

      public event PropertyChangedEventHandler PropertyChanged;
      
      public string Name
      {
          get { return name; }
          set
          {
              object before = Name;
              name = value;
              OnPropertyChanged("Name", before, Name);
          }
      }
      
      void OnPropertyChanged(PropertyChangedEventArgs e, object? argvaluebefore = null, object? argnewvalue = null, \[CallerMemberName\] string argcallername = "", \[CallerLineNumber\] int argcallerline = 0)
      {
          //How can I inject argvaluebefore and argvalue here ?
      	
      	PropertyChanged?.Invoke(this, e);
      }
      

      }

      public class Master
      {

      Person \_person = new();
      
      
      public Master()
      {
      
      	\_person.PropertyChanged += MyHandler;
      
      
      }
      
      
      private void MyHandler(object? sender, PropertyChangedEventArgs e)
      {
      
      	//How do I retrieve the curent values of property Name here plus the value before ?
      
      }
      

      }

      Hello, I need to retrieve the propery values of class Person in MyHandler of Class Master. Any ideas what I should do ? Regards, Chris

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

      You already have this posted in QA: don't post the same question in two places - all you will do is duplicate work and annoy people. Pick either the C# forum or the Q&A and stick with it. Annoyed people are less likely to be helpful than happy ones...

      "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

      A 1 Reply Last reply
      0
      • OriginalGriffO OriginalGriff

        You already have this posted in QA: don't post the same question in two places - all you will do is duplicate work and annoy people. Pick either the C# forum or the Q&A and stick with it. Annoyed people are less likely to be helpful than happy ones...

        "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!

        A Offline
        A Offline
        AtaChris
        wrote on last edited by
        #3

        Yea, the following code was one of the examples I tried:

        if (e.KeyCode == Keys.F1 && (e.Alt || e.Control || e.Shift))
        {
        //do sth
        }

        It is from the source you mentioned, but i does not work. Compiler says that

        KeyEventArgs

        does not contain a definition for Alt etc. Also there is no suggestion of how to fix it. These are my usings: using System; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Reflection; using System.Windows.Forms;

        OriginalGriffO 1 Reply Last reply
        0
        • A AtaChris

          Yea, the following code was one of the examples I tried:

          if (e.KeyCode == Keys.F1 && (e.Alt || e.Control || e.Shift))
          {
          //do sth
          }

          It is from the source you mentioned, but i does not work. Compiler says that

          KeyEventArgs

          does not contain a definition for Alt etc. Also there is no suggestion of how to fix it. These are my usings: using System; using System.ComponentModel; using System.ComponentModel.DataAnnotations; using System.Reflection; using System.Windows.Forms;

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

          That's because they don't generate keycodes: ALT on it's own does nothing, it needs a keystroke to make it useful - ALT+F2, CTRL+F4 for example. They are MODIFIER keys[^].

          "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