我的UserControl工作正常。今天,我爲usercontrol添加了一個簡單的接口。現在我可以在設計模式(XAML)中加載它,但在新的Window1.Xaml中使用UserControl時,它會崩潰。任何想法?WPF依賴屬性在GUI中使用我的界面崩潰
'類型'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
嗨Liz。 Thousend感謝你。現在,我的應用程序中有101個錯誤需要解決。這將花費很多時間。聽起來不好?我喜歡在他們的心中解決這些問題。感謝tipp。我希望這樣,我會找到一個解決方案。 – goldengel 2011-04-27 08:25:11