The UserControl is one I wrote called ColorSelector, and the *.vb file is as follows:
Partial Public Class ColorSelector : Inherits UserControl
Public Property Color() As Color
Get
Return CType(Me.rectColor.Fill, SolidColorBrush).Color
End Get
Set(ByVal value As Color)
Me.rectColor.Fill = New SolidColorBrush(value)
End Set
End Property
Public Property Header As String
Get
Return Me.txtHeader.Text
End Get
Set(value As String)
Me.txtHeader.Text = value
End Set
End Property
Public Sub New()
InitializeComponent()
End Sub
Private Sub ColorValueChanged(sender As Object, e As System.Windows.RoutedPropertyChangedEventArgs(Of Double)) Handles sldRed.ValueChanged, sldGreen.ValueChanged, sldBlue.ValueChanged
Me.Color = Color.FromArgb(255, CByte(Me.sldRed.Value), CByte(Me.sldGreen.Value), CByte(Me.sldBlue.Value))
End Sub
Private Sub ColorSelector_LayoutUpdated(sender As Object, e As System.EventArgs) Handles MyBase.LayoutUpdated
If (Me.Name = "clrOuter") Then
System.Diagnostics.Debug.WriteLine(String.Format("Color: {0} LayoutUpdated", Me.Color))
System.Diagnostics.Debug.WriteLine(String.Format("rectColor: {0} LayoutUpdated", CType(Me.rectColor.Fill, SolidColorBrush).Color))
End If
End Sub
Private Sub ColorSelector_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles MyBase.Loaded
If (Me.Name = "clrOuter") Then
System.Diagnostics.Debug.WriteLine(String.Format("Color: {0} Loaded", Me.Color))
System.Diagnostics.Debug.WriteLine(String.Format("rectColor: {0} Loaded", CType(Me.rectColor.Fill, SolidColorBrush).Color))
End If
Me.rectColor.Fill = New SolidColorBrush(Me.Color)
End Sub
Private Sub ColorSelector_SizeChanged(sender As Object, e As System.Windows.SizeChangedEventArgs) Handles MyBase.SizeChanged
If (Me.Name = "clrOuter") Then
System.Diagnostics.Debug.WriteLine(String.Format("Color: {0} SizeChanged", Me.Color))
System.Diagnostics.Debug.WriteLine(String.Format("rectColor: {0} SizeChanged", CType(Me.rectColor.Fill, SolidColorBrush).Color))
End If
End Sub
End Class
And the PhoneApplicationPage that uses it is Settings and has the following *.vb file:
Partial Public Class Settings : Inherits PhoneApplicationPage
Public Sub New()
InitializeComponent()
End Sub
Protected Overrides Sub OnNavigatedTo(e As System.Windows.Navigation.NavigationEventArgs)
If (CType(Application.Current, App).ColorsChanged) Then
Me.clrBackground.Color = CType(Application.Current, App).BackgroundColor
Me.clrOuter.Color = CType(Application.Current, App).OuterColor
Me.clrLine.Color = CType(Application.Current, App).LineColor
CType(Application.Current, App).ColorsChanged = False
End If
MyBase.OnNavigatedTo(e)
End Sub
Protected Overrides Sub OnNavigatedFrom(e As System.Windows.Navigation.NavigationEventArgs)
CType(Application.Current, App).BackgroundColor = Me.clrBackground.Color
CType(Application.Current, App).OuterColor = Me.clrOuter.Color
CType(Application.Current, App).LineColor = Me.clrLine.Color
CType(Application.Current, App).ColorsChanged = True
MyBase.OnNavigatedFrom(e)
End Sub
End Class
The unexpected property change is when the Color property of the ColorSelector changes from White to Red. This is only happening in the second instance of the ColorSelector (clrOuter), which is why my debug statements are inside if statements. When I run a Debug, I get the following in the Output:
Color: #FFFFFFFF SizeChanged
rectColor: #FFFFFFFF SizeChanged
Color: #FFFFFFFF LayoutUpdated
rectColor: #FFFFFFFF LayoutUpdated
Color: #FFFF0000 Loaded
rectColor: #FFFF0000 Loaded
Color: #FFFF0000 LayoutUpdated
rectColor: #FFFF0000 LayoutUpdated
You will notice that the point at which the Color property changes is between the first LayoutUpdated and the Loaded events, but I cannot find any code of mine that would be getting executed at that point. Any ideas? Thanks.