The designer shows that "Binding" can only be set on the DependencyProperty of the DependencyObject error
I created a custom control that has a DependencyProperty, and when I try to bind to it, I get an error in the constructor:
"Binding" cannot be set on the "ROCValue" property of type 'RocIndicator. "Binding" can only be set on a DependencyProperty DependencyObject.
Edit: I added a static modifier, but I still get this error. and yes i 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 it and run it it works. why is this error displayed?
source to share
I had one problem copying a UserControl from one project to another. I tried closing the solution, restarting Visual Studio and even restarting my computer. None of them worked.
Then I unloaded and reloaded the project and that seems to fix it. (Potentially Visual Studio build error).
To unload a project, right-click on your project in Solution Explorer and click Unload Project. Then right click and click Update Project.
source to share