M
MichTUV
Guest
Hallo,
i stuck at a behaviour i can't explain nor find any help in the documentation or various forums.
The following code is needed to explain my problem/ to ask my question. A simple WPF (VB.Net) app that has an combo box (BindingBox) that binds to a List (BindingData):
Imports System.ComponentModel
Class MainWindow
Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Protected Shadows Sub OnPropertyChanged(ByVal name As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(name))
End Sub
Dim _BindingData As New List(Of String)
Public Property BindingData As List(Of String)
Get
Return _BindingData
End Get
Set(ByVal value As List(Of String))
_BindingData = value
OnPropertyChanged("BindingData")
End Set
End Property
Sub New()
InitializeComponent()
DataContext = Me
BindingBox.ItemsSource = BindingData
BindingData.Add("Data 1")
BindingData.Add("Data 2")
End Sub
End Class
I added the binding to the code-behind, so i do not have to post the xaml. The behaviour is the same also if i establish the binding in the xaml.
Now to my problem/question.
The combo box BindingBox should only be updated if a new list is assigned to BindingData (source of the binding). But in this example BindingBox is also updated after i assigned BindingData to ItemsSource and added items to BindingData afterwards.
After the ui is fully loaded the combo box BindingBox is only updated if a new list is assinged to BindingData and not if items are added or removed (e.g. during a button click). Like it is described in the documentation.
So why is the behaviour different during the initialization? Why are the items displayed in the combo box after the assignment to ItemsSource? I assume that it has something to do with the initialization and loading of the ui and all its element.
Continue reading...
i stuck at a behaviour i can't explain nor find any help in the documentation or various forums.
The following code is needed to explain my problem/ to ask my question. A simple WPF (VB.Net) app that has an combo box (BindingBox) that binds to a List (BindingData):
Imports System.ComponentModel
Class MainWindow
Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Protected Shadows Sub OnPropertyChanged(ByVal name As String)
RaiseEvent PropertyChanged(Me, New PropertyChangedEventArgs(name))
End Sub
Dim _BindingData As New List(Of String)
Public Property BindingData As List(Of String)
Get
Return _BindingData
End Get
Set(ByVal value As List(Of String))
_BindingData = value
OnPropertyChanged("BindingData")
End Set
End Property
Sub New()
InitializeComponent()
DataContext = Me
BindingBox.ItemsSource = BindingData
BindingData.Add("Data 1")
BindingData.Add("Data 2")
End Sub
End Class
I added the binding to the code-behind, so i do not have to post the xaml. The behaviour is the same also if i establish the binding in the xaml.
Now to my problem/question.
The combo box BindingBox should only be updated if a new list is assigned to BindingData (source of the binding). But in this example BindingBox is also updated after i assigned BindingData to ItemsSource and added items to BindingData afterwards.
After the ui is fully loaded the combo box BindingBox is only updated if a new list is assinged to BindingData and not if items are added or removed (e.g. during a button click). Like it is described in the documentation.
So why is the behaviour different during the initialization? Why are the items displayed in the combo box after the assignment to ItemsSource? I assume that it has something to do with the initialization and loading of the ui and all its element.
Continue reading...