Is it possible to pass changes made to properties in an ObservableCollection back to the main CollectionControl?
Suppose I have a simple CollectionControl defined...
Suppose I have a simple CollectionControl defined...
<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="CollectionControlElements"
VerticalAlignment="Top"
Width="479"
>
</xctk:CollectionControl>
</StackPanel>
</Grid>
</Window>
with code behind...Class MainWindow
Public myConstruction As New clsConstruction
Public myConstructionCollection As New ObservableCollection(Of clsConstruction)
Public Sub New()
' This call is required by the designer.
InitializeComponent()
CollectionControlElements.DataContext = myConstructionCollection
CollectionControlElements.NewItemTypes = New ObservableCollection(Of System.Type)() From {GetType(clsConstruction)}
End Sub
End Class
where clsConstruction isImports 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 clsLayer)
Public myDescription As String
Public myTotalThickness As Double
Public Sub New()
myDescription = "New Construction"
End Sub
Public Property LayerCollection As ObservableCollection(Of clsLayer)
Get
Return myLayerCollection
End Get
Set(value As ObservableCollection(Of clsLayer))
myLayerCollection = value
OnPropertyChanged(New PropertyChangedEventArgs("LayerCollection"))
OnPropertyChanged(New PropertyChangedEventArgs("TotalThickness"))
End Set
End Property
Public Property Description As String
Get
Return myDescription
End Get
Set(value As String)
myDescription = value
OnPropertyChanged(New PropertyChangedEventArgs("Description"))
End Set
End Property
ReadOnly Property TotalThickness() As Double
Get
myTotalThickness = 0.0
If Not IsNothing(LayerCollection) Then
If LayerCollection.Count > 0 Then
For i = 0 To LayerCollection.Count - 1
myTotalThickness = myTotalThickness + LayerCollection(i).Thickness
Next
End If
Return Math.Round(myTotalThickness, 3)
End If
End Get
End Property
End Class
which contains observablecollection of clsLayer, where clsLayer is...Imports System.ComponentModel
Imports System.Collections.ObjectModel
Public Class clsLayer
Implements INotifyPropertyChanged
Public myThickness As Double
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 Sub New()
End Sub
Public Property Thickness() As Double
Get
Return myThickness
End Get
Set(ByVal value As Double)
myThickness = value
OnPropertyChanged(New PropertyChangedEventArgs("Thickness"))
End Set
End Property
End Class
I want to be able to change the thickness property in the clsLayer class (via the clsLayer CollectionControl that is automatically generated) and have that change instantly reflected in the clsConstuction CollectionControl.