0
votes

I am using VB.NET and WPF within Visual Studio 2010 Express.

Currently, I have:

  • A DataGrid by the name of downloadListDG. This has a column which is a template containing an image.
  • An ObservableCollection of a custom DownloadListItem class.
  • This DownloadListItem has a public property which is another custom class.
  • This class has a private dim which is a StateType (a custom enum), and a public readonly property which returns a string depending on what the StateType is (actually an image URI if you're curious).
  • The DownloadListItem also has a public property which just returns the StateType (this is just for binding purposes)

My problem is that whenever the StateType changes, the image column in the DataGrid does not change. I have been trying to use the IPropertyChangedNofity, but nothing changes, so either I'm using it incorrectly or I need to use another method.

Implements INotifyPropertyChanged

Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged

AddHandler ControllerRef.StateChanged, AddressOf StateChangeHandler

Private Sub StateChangeHandler(NewState As State)
    MsgBox(NewState)
    RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs("CurrentState"))
End Sub

Thanks in advance

1

1 Answers

1
votes

Make sure the PropertyChanged event is notifying the UI of the property name you are bound to, not the property that triggers the change. Example:

Imports System.ComponentModel

Public Class DownloadListItem : Implements INotifyPropertyChanged

Friend Enum StateEnum
    State1 = 0
    State2 = 1
End Enum

Private _CurrentState As StateEnum

Private Sub ChangeEnumValue(NewValue As StateEnum)
    _CurrentState = NewValue
    OnPropertyChanged("ImageURI")
End Sub

Public ReadOnly Property ImageURI As String
    Get
        ' TODO: Implement conditional logic to return proper value based on CurrentState Enum
    End Get
End Property

Public Event PropertyChanged(sender As Object, e As PropertyChangedEventArgs) Implements INotifyPropertyChanged.PropertyChanged

Protected Sub OnPropertyChanged(PropertyName As String)
    RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(PropertyName))
End Sub

End Class