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. Raise an event whenever a property’s value changed ?

Raise an event whenever a property’s value changed ?

Scheduled Pinned Locked Moved C#
tutorialquestion
8 Posts 4 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.
  • M Offline
    M Offline
    Mohammad Dayyan
    wrote on last edited by
    #1

    Hi everybody. There is a property, it's named ImageFullPath1

    public string ImageFullPath1 {get; set; }

    I'm gonna fire an event whenever its value changed. I know I can beware of changing with INotifyPropertyChanged, but I wanna do it with events. I don't know how I should do it. Could you please guide me? Thanks.

    N T 2 Replies Last reply
    0
    • M Mohammad Dayyan

      Hi everybody. There is a property, it's named ImageFullPath1

      public string ImageFullPath1 {get; set; }

      I'm gonna fire an event whenever its value changed. I know I can beware of changing with INotifyPropertyChanged, but I wanna do it with events. I don't know how I should do it. Could you please guide me? Thanks.

      N Offline
      N Offline
      Not Active
      wrote on last edited by
      #2

      INotifyPropertyChanged uses events and is there just for what you are asking.


      I know the language. I've read a book. - _Madmatt

      E 1 Reply Last reply
      0
      • N Not Active

        INotifyPropertyChanged uses events and is there just for what you are asking.


        I know the language. I've read a book. - _Madmatt

        E Offline
        E Offline
        Ennis Ray Lynch Jr
        wrote on last edited by
        #3

        I just hate the fact that it uses a string, however.

        Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

        T 1 Reply Last reply
        0
        • E Ennis Ray Lynch Jr

          I just hate the fact that it uses a string, however.

          Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

          T Offline
          T Offline
          The Man from U N C L E
          wrote on last edited by
          #4

          Use the alternative approach with the same result. You need a specifically named event with the default eventArgs the name must be YOURPROPERTYChanged . For best practice also supply and OnYOURPROPERTYChanged method as well. e.g.

          private string _MyProperty;

          public string MyProperty {
          Get { return this._MyProperty; }
          Set {
          If (this._MyProperty != value){
          this._MyProperty = value;
          this.OnMyPropertyChanged(EventArgs.Empty);
          }
          }
          }

          public virtual void OnMyPropertyChanged(EventArgs e){
          if (this.MyPropertyChanged != null){
          this.MyPropertyChanged(this, e);
          }
          }

          public EventHandler MyPropertyChanged;

          If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

          E 1 Reply Last reply
          0
          • T The Man from U N C L E

            Use the alternative approach with the same result. You need a specifically named event with the default eventArgs the name must be YOURPROPERTYChanged . For best practice also supply and OnYOURPROPERTYChanged method as well. e.g.

            private string _MyProperty;

            public string MyProperty {
            Get { return this._MyProperty; }
            Set {
            If (this._MyProperty != value){
            this._MyProperty = value;
            this.OnMyPropertyChanged(EventArgs.Empty);
            }
            }
            }

            public virtual void OnMyPropertyChanged(EventArgs e){
            if (this.MyPropertyChanged != null){
            this.MyPropertyChanged(this, e);
            }
            }

            public EventHandler MyPropertyChanged;

            If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

            E Offline
            E Offline
            Ennis Ray Lynch Jr
            wrote on last edited by
            #5

            I don't recall asking a question to which this was the answer.

            Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

            T 1 Reply Last reply
            0
            • E Ennis Ray Lynch Jr

              I don't recall asking a question to which this was the answer.

              Need custom software developed? I do custom programming based primarily on MS tools with an emphasis on C# development and consulting. A man said to the universe: "Sir I exist!" "However," replied the universe, "The fact has not created in me A sense of obligation." --Stephen Crane

              T Offline
              T Offline
              The Man from U N C L E
              wrote on last edited by
              #6

              Sorry, replied at the wrong level in the thread. My appologies

              If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

              1 Reply Last reply
              0
              • M Mohammad Dayyan

                Hi everybody. There is a property, it's named ImageFullPath1

                public string ImageFullPath1 {get; set; }

                I'm gonna fire an event whenever its value changed. I know I can beware of changing with INotifyPropertyChanged, but I wanna do it with events. I don't know how I should do it. Could you please guide me? Thanks.

                T Offline
                T Offline
                The Man from U N C L E
                wrote on last edited by
                #7

                Posted in reply to the wrong message earlier. Apologies. Use the alternative approach with the same result. You need a specifically named event with the default eventArgs the name must be YOURPROPERTYChanged . For best practice also supply and OnYOURPROPERTYChanged method as well. e.g.

                private string _MyProperty;

                public string MyProperty {
                Get { return this._MyProperty; }
                Set {
                If (this._MyProperty != value){
                this._MyProperty = value;
                this.OnMyPropertyChanged(EventArgs.Empty);
                }
                }
                }

                public virtual void OnMyPropertyChanged(EventArgs e){
                if (this.MyPropertyChanged != null){
                this.MyPropertyChanged(this, e);
                }
                }

                public EventHandler MyPropertyChanged;

                If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

                M 1 Reply Last reply
                0
                • T The Man from U N C L E

                  Posted in reply to the wrong message earlier. Apologies. Use the alternative approach with the same result. You need a specifically named event with the default eventArgs the name must be YOURPROPERTYChanged . For best practice also supply and OnYOURPROPERTYChanged method as well. e.g.

                  private string _MyProperty;

                  public string MyProperty {
                  Get { return this._MyProperty; }
                  Set {
                  If (this._MyProperty != value){
                  this._MyProperty = value;
                  this.OnMyPropertyChanged(EventArgs.Empty);
                  }
                  }
                  }

                  public virtual void OnMyPropertyChanged(EventArgs e){
                  if (this.MyPropertyChanged != null){
                  this.MyPropertyChanged(this, e);
                  }
                  }

                  public EventHandler MyPropertyChanged;

                  If you have knowledge, let others light their candles at it. Margaret Fuller (1810 - 1850) [My Articles]  [My Website]

                  M Offline
                  M Offline
                  Mohammad Dayyan
                  wrote on last edited by
                  #8

                  Thanks

                  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