Probably your class (model) is not inherited from DependencyObject, in contrast with the class where these functions work.
Check some recommendations too:
This browser is no longer supported.
Upgrade to Microsoft Edge to take advantage of the latest features, security updates, and technical support.
I'm trying to define a DependencyProperty in a viewmodel class. Here's what I've got:
public static readonly DependencyProperty SolutionIDProperty = DependencyProperty.Register("SolutionID", typeof(long), typeof(SolutionViewModel));
public long SolutionID
{
get { return (long)GetValue(SolutionIDProperty); }
set { SetValue(SolutionIDProperty, value); }
}
Both the GetValue() and SetValue() calls raise a CS0103 error. I'm including the System.Windows assembly and put a using statement at the top of the viewmodel class. GetValue() and SetValue() both are defined in DependencyObject class, which is in System.Windows. Like I said I've got the assembly referenced and included in the viewmodel's class at the top of the class.
What really confuses me is that a colleague of my is using the DependencyProperty in nearly the same way, and it works perfectly for him. Here's what he's got:
public static readonly DependencyProperty ButtonIndexProperty = DependencyProperty.Register("ButtonIndex", typeof(int), typeof(CoreButtonList));
public int ButtonIndex
{ get
{ return (int)GetValue(ButtonIndexProperty);
}
set
{ SetValue(ButtonIndexProperty, value);
}
}
His project includes the System.Windows assembly in the references, like mine does. And he's got a using statement at the code of the file, like mine done.
The only differences I can see are these:
Other than those three differences, everything else is the same. I find it incredibly hard to believe that the problem is either #1 or #2, above. Could #3 be what's causing me to get a CS0103 error when I tried to build my solution? If so, how? Or is there something else going on?
Probably your class (model) is not inherited from DependencyObject, in contrast with the class where these functions work.
Check some recommendations too:
I modify your SoultionID like :
public static long GetSolutionID(DependencyObject obj)
{
return (long)obj.GetValue(SolutionIDProperty);
}
public static void SetSolutionID(DependencyObject obj, long value)
{
obj.SetValue(SolutionIDProperty, value);
}
public static readonly DependencyProperty SolutionIDProperty = DependencyProperty.Register("SolutionID", typeof(long), typeof(SolutionViewModel));
And use it in xaml like:
<TextBlock Width="420" Height="150" TextWrapping="Wrap" Background="Azure" local:SolutionViewModel.SolutionID="5" ></TextBlock>
It runs no error.
If the response is helpful, please click "Accept Answer" and upvote it.
Note: Please follow the steps in our documentation to enable e-mail notifications if you want to receive the related email notification for this thread.