我创建了一个具有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
发布评论