My UserControl is working fine. Today I added a simple Interface to the usercontrol. Now I can load it in design mode (XAML) but when using the UserControl in a new Window1.Xaml it crashes. Any idea?
'The invocation of the constructor on type 'OUTPUT___WPF01.ucUpDownBox' that matches the specified binding constraints threw an exception.
''' <summary>
''' BorderColor Dependency Property
''' </summary>
Public Shared ReadOnly BorderColorProperty As DependencyProperty = _
DependencyProperty.Register("BorderColor", GetType(System.Windows.Media.Color), GetType(ucUpDownBox), _
New FrameworkPropertyMetadata(System.Windows.Media.Color.FromArgb(255, 50, 50, 50), _
FrameworkPropertyMetadataOptions.None, _
AddressOf OnBorderColorChanged))
''' <summary>
''' Gets or sets the BorderColor property. This dependency property
''' indicates ....
''' </summary>
Public Property BorderColor() As System.Windows.Media.Color Implements IButton.Color '<--- IButton.Color is the interface with Media.Col开发者_JAVA百科or
Get
Return CType(GetValue(BorderColorProperty), System.Windows.Media.Color)
End Get
Set(ByVal value As System.Windows.Media.Color)
SetValue(BorderColorProperty, value)
End Set
End Property
''' <summary>
''' Handles changes to the BorderColor property.
''' </summary>
Private Overloads Shared Sub OnBorderColorChanged(ByVal d As DependencyObject, ByVal e As DependencyPropertyChangedEventArgs)
Dim target As ucUpDownBox = CType(d, ucUpDownBox)
Dim oldBorderColor As System.Windows.Media.Color = CType(e.OldValue, System.Windows.Media.Color)
Dim newBorderColor As System.Windows.Media.Color = target.BorderColor
target.OnBorderColorChanged(oldBorderColor, newBorderColor)
End Sub
''' <summary>
''' Provides derived classes an opportunity to handle changes to the BorderColor property.
''' </summary>
Protected Overridable Overloads Sub OnBorderColorChanged(ByVal oldBorderColor As System.Windows.Media.Color, ByVal newBorderColor As System.Windows.Media.Color)
Dim uc As ucUpDownBox = CType(Me, ucUpDownBox)
uc.Col1A.Color = AddLuminance(BorderColor, 60)
uc.Col1B.Color = AddLuminance(BorderColor, -60)
End Sub
That usually happens when default value's type is not identical to dependency property's type.
E.g. 0 instead of 0.0 for double, or Color instead of Brush.
Also can be caused by using non assigned (null) property in constructor.
"The invocation of the constructor on type ... that matches the specified binding constraints threw an exception"
This error typically means that there was a runtime error parsing the xaml code. Which of course doesn't tell you much. So you need to get more information. Basically the exception that you are seeing is just a general error, we want to see what lead up to this problem.
To get the real exception (or what we call the 'inner exception'): - activate the catching of all exceptions thrown in Visual Studio. Open Debug > Exceptions and activate the checkbox in the "thrown" column for "Common Language Runtime Exceptions".
Now trigger the crash again, and see what you get. Ideally we want to see the stack trace. If you look in the trace, you will probably see some part of your code being called. Take a look at this code and see if you can isolate the problem from there.
If you are still stuck, then post some code, and the stack trace in your question, and we'll see what we can do from there.
Sometimes the 'output' window will also give you some information.
精彩评论