I am studying dependency properties. I read a lot of posts and books, but still I do not know.
Below is the program I wrote to find out. Some error in this, please help in resolving. I have some questions.
- The main use of the user-defined Dependency property element for change notification?
- I found the "IsDefaultProperty" code for Button in a WPF text editor. Does this mean that the IsDefault 'property is a dependency property?
- Why did they show this code? Does this mean, inside, in the Button class, that it is defined like this? (Did they show internal code?) Or did they show how to define as custom?
Here is my code:
namespace DependencyProperties { public class Contact { private int id=100; private string name="shri"; public static readonly DependencyProperty IsPresentProperty; public int ID { get { return id; } } public string NAME { get { return name; } } static Contact() { IsPresentProperty = DependencyProperty.Register("IsPresent", typeof(bool),typeof(Contact),new FrameworkPropertyMetadata(false,new PropertyChangedCallback(OnIsPresentChanged))); } public bool Present { get { return (bool)GetValue(Contact.IsPresentProperty); } set { SetValue(Contact.IsPresentProperty, value); } } private static void OnIsPresentChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) { } } }
And I see an error:
> Error: GetValue and SetValue does not exist in the current context
source share