【发布时间】:2011-08-13 08:00:22
【问题描述】:
我的 UserControl 工作正常。今天我为用户控件添加了一个简单的界面。现在我可以在设计模式 (XAML) 中加载它,但是在新的 Window1.Xaml 中使用 UserControl 时它会崩溃。有什么想法吗?
'在匹配指定绑定约束的类型'OUTPUT___WPF01.ucUpDownBox'上调用构造函数引发异常。
''' <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.Color
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
【问题讨论】:
标签: wpf vb.net properties interface dependencies