Hi
I have been searching fo days now to resolve a binding issue i am having and every solution i found has come up short and not worked. All i can think of is that what i am trying to do is not supported and cannot be done (But I Doubt it.) Here is the scenario.....
I have a class called SupportCall
Within the class there is an ObservableCollection of a SupportAction object.
Based on the security rights of the user viewing the support call they can see All SupportAction's or just public ones. i expose the lists By having two properties as shown below.
Public ReadOnly Property Actions() As IList(Of SupportAction)
Get
Try
Dim found As IQueryable(Of SupportAction) = Nothing
found = From a As SupportAction In _actions.AsQueryable _
Order By a.CreateDate Descending
Return found.ToObservableCollection
Catch ex As Exception
Throw ex
End Try
End Get
End Property
And....
Public ReadOnly Property ActionsGeneral() As IList(Of SupportAction)
Get
Try
Dim found As IQueryable(Of SupportAction) = Nothing
found = From a As SupportAction In _actions.AsQueryable _
Where a.IsInternal = False Order By a.CreateDate Descending
Return found.ToObservableCollection
Catch ex As Exception
Throw ex
End Try
End Get
End Property
i use an extention fucntion to convert the IQueryable to an ObservableCollection. The function is below.....
<Extension()> _
Public Function ToObservableCollection(Of T)(ByVal MyCollection As IEnumerable(Of T)) As ObservableCollection(Of T)
Try
Dim c As New ObservableCollection(Of T)(MyCollection)
Return c
Catch ex As Exception
Throw New NotSupportedException(ex.InnerException.Message)
End Try
End Function
In my front end WPF application i use one of the properties to populate a datagrid like so....
dgActions.ItemsSource = _CurrentCall.Actions
i have a button that then adds a new action. This is done via a method within the SupportCall Object. The method is below....
Public Sub AddAction(ByVal UserID As Integer, ByVal Description As String, ByVal HasAtt As Boolean, ByVal AttFileName As String, ByVal Type As Integer, ByVal Internal As Boolean)
Try
Dim sa As New SupportAction(_callid, UserID, Description, HasAtt, AttFileName, Type, Internal, _datasource, _DSusername, _DSPassword)
_actions.Add(sa)
NotifyPropertyChanged("Actions")
NotifyPropertyChanged("ActionsGeneral")
Catch ex As Exception
Throw ex
End Try
End Sub
my problem is that when i fire the AddAction sub i expect the WPF datagrid to reflect the change as its source has been set to be an ObservableCollection. Unfortunatley nothing happens. I have to close the form and reload the view the new action in the grid. I need to be able to bind the Datagrid.ItemSource dynamically in code rather than XAML to apply user security features. Can anyone tell me what the hell i am doing wrong here because i just cant get it to work.... Please Help Someone......