Reputation: 101
I am getting an error in the following dependency property
Error:
Does not contain a definition for 'GetValue' and no extension method 'GetValue' accepting a first argument of type could be found (are you missing a using directive or an assembly reference?)
My DP:
using System;
using System.Linq;
using System.Windows;
namespace NameSpace
{
public class RadWindowProperties
{
public static readonly DependencyProperty ScreenSubtitleProperty = DependencyProperty.Register("ScreenSubtitle", typeof(string), typeof(RadWindowProperties), new PropertyMetadata(String.Empty));
public string ScreenSubtitle
{
get
{
return (string)this.GetValue(ScreenSubtitleProperty);
}
set
{
this.SetValue(ScreenSubtitleProperty, value);
}
}
}
}
Upvotes: 0
Views: 8097
Reputation: 1436
Your class must inherit from DependencyObject, just change the class definition:
public class RadWindowProperties : DependencyObject
Upvotes: 3
Reputation: 1881
According to msdn GetValue method Returns the current effective value of a dependency property on a dependency object.
for example if you create a dependency property like this
public static readonly DependencyProperty BoundPasswordProperty =
DependencyProperty.RegisterAttached("BoundPassword", typeof(string), typeof(PasswordBoxAssistant), new PropertyMetadata(string.Empty, OnBoundPasswordChanged));
You can use GetValue method to get the value of particular instance of DependencyObject.see the below code
private static void OnBoundPasswordChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
PasswordBox box = d as PasswordBox;
string strValue=GetBoundPassword(d);
}
public static string GetBoundPassword(DependencyObject dp)
{
return (string)dp.GetValue(BoundPasswordProperty);
}
so your class must inherit from DependencyObject class before you can use GetValue method.
Upvotes: 2