设计器显示“绑定”只能在DependencyObject错误的DependencyProperty上设置(designer shows A 'Binding' can only b

编程入门 行业动态 更新时间:2024-10-08 20:32:25
设计器显示“绑定”只能在DependencyObject错误的DependencyProperty上设置(designer shows A 'Binding' can only be set on a DependencyProperty of a DependencyObject error)

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

''绑定'不能在'RocIndicator'类型的'ROCValue'属性上设置,'绑定'只能在DependencyObject的DependencyProperty上设置。

编辑:我已经添加了静态修饰符,但我仍然得到该错误。 是的,我重新启动了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"/>

但是当我建立和运行它的作品。 为什么会出现此错误?

I've created a user control that has a DependencyProperty, and when I try binding to it I get an error in the designer:

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

Edit: I've added the static modifier, but I still get that error. and yes, I've restarted 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); } } }

this is the XAML:

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

but when I build & run it works. why is this error showing?

最满意答案

依赖属性声明必须是static :

public static readonly DependencyProperty ROCValueProperty ...

Dependency property declaration must be static:

public static readonly DependencyProperty ROCValueProperty ...

更多推荐

DependencyProperty,错误,public,I've,电脑培训,计算机培训,IT培训"/> <meta n

本文发布于:2023-07-18 07:41:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1157096.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:绑定   错误   只能在   DependencyObject   DependencyProperty

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!