gpt4 book ai didi

使用我的界面在 GUI 中的 WPF 依赖项属性崩溃

转载 作者:行者123 更新时间:2023-12-04 06:28:01 25 4
gpt4 key购买 nike

我的用户控件工作正常。今天我为用户控件添加了一个简单的界面。现在我可以在设计模式 (XAML) 中加载它,但是在新的 Window1.Xaml 中使用 UserControl 时它会崩溃。任何的想法?

'对与指定绑定(bind)约束匹配的'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

最佳答案

当默认值的类型与依赖属性的类型不同时,通常会发生这种情况。

例如。 0 而不是 0.0 表示 double ,或颜色而不是画笔。

也可能是由于在构造函数中使用未分配 (null) 属性引起的。

关于使用我的界面在 GUI 中的 WPF 依赖项属性崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5795689/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com