WPF Dependancy Property issue
-
Hi. I have a class library with a class that requires a dependanct property to be included. So I've referenced WindowsBase and inserted Using System.Window. I've used the following code to set up the dependancy property:
public bool IsChecked { get { return (bool)GetValue(IsCheckedProperty); } set { SetValue(IsCheckedProperty, value); } } public static readonly DependencyProperty IsCheckedProperty = DependencyProperty.Register("IsChecked", typeof(bool), typeof(EdgeProperty), new UIPropertyMetadata(false));
I can see that the DependencyProperty class is referenced and all is fine. However, the methods 'GetValue' and 'SetValue' do not exist. I know these are from the DependancyObject class, which is referenced. Anybody know what's going on? Cheers, Chris -
Hi. I have a class library with a class that requires a dependanct property to be included. So I've referenced WindowsBase and inserted Using System.Window. I've used the following code to set up the dependancy property:
public bool IsChecked { get { return (bool)GetValue(IsCheckedProperty); } set { SetValue(IsCheckedProperty, value); } } public static readonly DependencyProperty IsCheckedProperty = DependencyProperty.Register("IsChecked", typeof(bool), typeof(EdgeProperty), new UIPropertyMetadata(false));
I can see that the DependencyProperty class is referenced and all is fine. However, the methods 'GetValue' and 'SetValue' do not exist. I know these are from the DependancyObject class, which is referenced. Anybody know what's going on? Cheers, ChrisWhat does your class inherit from?
Deja View - the feeling that you've seen this post before.
-
Hi. I have a class library with a class that requires a dependanct property to be included. So I've referenced WindowsBase and inserted Using System.Window. I've used the following code to set up the dependancy property:
public bool IsChecked { get { return (bool)GetValue(IsCheckedProperty); } set { SetValue(IsCheckedProperty, value); } } public static readonly DependencyProperty IsCheckedProperty = DependencyProperty.Register("IsChecked", typeof(bool), typeof(EdgeProperty), new UIPropertyMetadata(false));
I can see that the DependencyProperty class is referenced and all is fine. However, the methods 'GetValue' and 'SetValue' do not exist. I know these are from the DependancyObject class, which is referenced. Anybody know what's going on? Cheers, ChrisChris, Using Visual Studio, add a new project to your solution, a WPF Custom Control library. After you create it, you can delete the Themes folder and the custom control it creates by default. Now move your class into this project and everything will work fine.
Cheers, Karl
» CodeProject 2008 MVP » Microsoft MVP - Client App Dev My Blog | Mole's Home Page | MVP ProfileJust a grain of sand on the worlds beaches.
-
Hi. I have a class library with a class that requires a dependanct property to be included. So I've referenced WindowsBase and inserted Using System.Window. I've used the following code to set up the dependancy property:
public bool IsChecked { get { return (bool)GetValue(IsCheckedProperty); } set { SetValue(IsCheckedProperty, value); } } public static readonly DependencyProperty IsCheckedProperty = DependencyProperty.Register("IsChecked", typeof(bool), typeof(EdgeProperty), new UIPropertyMetadata(false));
I can see that the DependencyProperty class is referenced and all is fine. However, the methods 'GetValue' and 'SetValue' do not exist. I know these are from the DependancyObject class, which is referenced. Anybody know what's going on? Cheers, ChrisYou need to inherit from DependencyObject not just reference it.
-
You need to inherit from DependencyObject not just reference it.
Cheers guys, that worked.