I must be doing something wrong again with CollectionControls but I can't get it to bind properly.
Using the following code I expected to see the myConstruction.LayerCollection.Count increase after the CollectionControl Add button has been clicked but it doesn't. Note that CollectionControl1.Items.Count does update.
(Counts are displayed hen the cmdCount button is clicked)
The xaml
Any help much appreciated.
Using the following code I expected to see the myConstruction.LayerCollection.Count increase after the CollectionControl Add button has been clicked but it doesn't. Note that CollectionControl1.Items.Count does update.
(Counts are displayed hen the cmdCount button is clicked)
The xaml
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="800" Width="525" xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit">
<Grid>
<StackPanel>
<xctk:CollectionControl Height="240"
HorizontalAlignment="Left"
Name="CollectionControl1"
VerticalAlignment="Top"
Width="479"
>
<xctk:CollectionControl.Style>
<Style TargetType="xctk:CollectionControl">
<Style.Resources>
<Style TargetType="ListBox">
<Setter Property="ItemTemplate">
<Setter.Value>
<DataTemplate>
<TextBlock Text="{Binding DisplayedName}"
Background="LightGreen" />
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</Style.Resources>
</Style>
</xctk:CollectionControl.Style>
</xctk:CollectionControl>
<Button Name="cmdCount" Content="MaterialCollection.Count"/>
</StackPanel>
</Grid>
</Window>
The modelClass MainWindow
Public myConstruction As New clsConstruction
Public Sub New()
' This call is required by the designer.
InitializeComponent()
CollectionControl1.DataContext = myConstruction.LayerCollection
CollectionControl1.ItemsSource = myConstruction.LayerCollection
CollectionControl1.NewItemTypes = New ObservableCollection(Of System.Type)() From {GetType(clsConstruction)}
End Sub
Private Sub cmdCount_Click(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles cmdCount.Click
MsgBox(myConstruction.LayerCollection.Count & CollectionControl1.Items.Count)
End Sub
End Class
where clsMaterial contains:Imports System.ComponentModel
Imports System.Collections.ObjectModel
Public Class clsMaterial
Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Public Sub OnPropertyChanged(ByVal e As PropertyChangedEventArgs)
If Not PropertyChangedEvent Is Nothing Then
RaiseEvent PropertyChanged(Me, e)
End If
End Sub
Public myLWEmissivityOut As Double
Public myLWEmissivityIn As Double
Public myDisplayedName As String
Public Sub New()
myDisplayedName = "DefaultName"
myLWEmissivityOut = 0.0
myLWEmissivityIn = 0.0
'OnPropertyChanged(New PropertyChangedEventArgs("Thickness"))
End Sub
Public Sub New( _
ByVal newDisplayedName As String,
ByVal newLWEmissivityOut As Double,
ByVal newLWEmissivityIn As Double)
myDisplayedName = newDisplayedName
myLWEmissivityOut = newLWEmissivityOut
myLWEmissivityIn = newLWEmissivityIn
End Sub
Public Property DisplayedName() As String
Get
Return myDisplayedName
End Get
Set(ByVal value As String)
myDisplayedName = value
End Set
End Property
Public Property LWEmissivityOut() As Double
Get
Return myLWEmissivityOut
End Get
Set(ByVal value As Double)
myLWEmissivityOut = value
End Set
End Property
Public Property LWEmissivityIn() As Double
Get
Return myLWEmissivityIn
End Get
Set(ByVal value As Double)
myLWEmissivityIn = value
End Set
End Property
End Class
and clsConstruction contains:Imports System.ComponentModel
Imports System.Collections.ObjectModel
Public Class clsConstruction
Implements INotifyPropertyChanged
Public Event PropertyChanged As PropertyChangedEventHandler Implements INotifyPropertyChanged.PropertyChanged
Public Sub OnPropertyChanged(ByVal e As PropertyChangedEventArgs)
If Not PropertyChangedEvent Is Nothing Then
RaiseEvent PropertyChanged(Me, e)
End If
End Sub
Public myLayerCollection As New ObservableCollection(Of clsMaterial)
Public Sub New()
myLayerCollection.Add(New clsMaterial())
End Sub
Public Property LayerCollection As ObservableCollection(Of clsMaterial)
Get
Return myLayerCollection
End Get
Set(value As ObservableCollection(Of clsMaterial))
myLayerCollection = value
OnPropertyChanged(New PropertyChangedEventArgs("LayerCollection"))
End Set
End Property
End Class
Hopefully this is my final CollectionControl related question!Any help much appreciated.