gpt4 book ai didi

c# - 设计器显示 A 'Binding' can only be set on a DependencyProperty of a DependencyObject 错误

转载 作者:太空狗 更新时间:2023-10-29 22:16:05 25 4
gpt4 key购买 nike

我创建了一个具有 DependencyProperty 的用户控件,当我尝试绑定(bind)到它时,我在设计器中遇到错误:

" 'Binding' cannot be set on the 'ROCValue' property of type 'RocIndicator'. A 'Binding' can only be set on a DependencyProperty of a DependencyObject.

编辑:我已经添加了 static 修饰符,但我仍然遇到该错误。是的,我已经重新启动了 visual studio。

public partial class RocIndicator : UserControl
{
public static readonly DependencyProperty ROCValueProperty =
DependencyProperty.Register("ROCValue", typeof(double), typeof(RocIndicator),
new FrameworkPropertyMetadata(0.0, new PropertyChangedCallback(ValueChanged)));


public double ROCValue
{
get { return (double)GetValue(ROCValueProperty); }
set { SetValue(ROCValueProperty, value); }
}
}

这是 XAML:

<View:RocIndicator ROCValue="{Binding ROC}" Margin="0,10,0,0" HorizontalAlignment="Center" Width="35"/>

但是当我构建并运行它时它会工作。为什么会显示此错误?

最佳答案

依赖属性声明必须是static:

public static readonly DependencyProperty ROCValueProperty ...

关于c# - 设计器显示 A 'Binding' can only be set on a DependencyProperty of a DependencyObject 错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25286007/

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