Results 1 to 4 of 4

Thread: Using Enums with INotifyPropertyChanged

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2010
    Posts
    64

    Using Enums with INotifyPropertyChanged

    I have a public property, "Status" that is an enum. I have a setter method that changes the status and raises the PropertyChanged event. However, the WinForms user interface is not properly updating. I'm pretty sure it's because Status is an enum. Although I was thinking enum was a reference type but I guess it's a value type. Does INotifyPropertyChanged work the same with reference and value types?

    Code:
        ''' <summary>
        ''' Set's the BOL's status.
        ''' </summary>
        ''' <param name="Status">The new status to set the BOL to.</param>
        Public Sub SetStatus(ByVal Status As BillOfLadingStatus)
            'todo: change to private, had as public for testing purposes.
            Me._Status = Status
            Me.OnPropertyChanged(New PropertyChangedEventArgs("Status"))
        End Sub
    
        Private _Status As BillOfLadingStatus
        ''' <summary>
        ''' The status of the BOL 
        ''' </summary>
        Public ReadOnly Property Status As BillOfLadingStatus
            Get
                Return Me._Status
            End Get
        End Property

  2. #2
    PowerPoster
    Join Date
    Mar 2002
    Location
    UK
    Posts
    4,780

    Re: Using Enums with INotifyPropertyChanged

    You are calling a method called OnPropertyChanged, you are not actually raising an event. I have not seen the NotifyPropertyChanged system in use, but even the example shows:

    Code:
    RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(info))
    So surely you would call
    Code:
    RaiseEvent OnPropertyChanged(New PropertyChangedEventArgs("Status"))
    btw, why are you declaring a SetStatus method instead of just using the Set declaration of the Status property?

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2010
    Posts
    64

    Re: Using Enums with INotifyPropertyChanged

    The OnPropertyChanged method raises the event. It's part of the parent class, BusinessObject that many of my classes inherit from. Maybe that is part of the reason it isn't working, because it's the parent class raising the event? I wouldn't think so... in fact pretty sure I have used the same pattern before without problems (but with String properties).

    As far as why I'm using the SetStatus() method instead of setting the value as part of the property... the code still isn't complete and the SetStatus() method will probably have other side effects before I'm finished that I think would be cleaner to keep separate from the property itself. I agree, as is, it doesn't make much sense

  4. #4

    Thread Starter
    Lively Member
    Join Date
    May 2010
    Posts
    64

    Re: Using Enums with INotifyPropertyChanged

    Yup, I think that was the problem. The event has to be raised directly from the class implementing the property, not from the parent class.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width