DependencyProperty problem
-
Hello all, Im working on an ColorPicker user control and have problems registering DependencyPropertys. I try to register a new DependencyProperty in Visual Studio 2008 and all is working fine so far. Now i open Expression blend, add an reference to the ColorPicker.dll, and add a new instance to the window. When i now build the solution i get an exeption: "the property IsCurrentColor has allready been registerd from _ColorPicker" and the usercontrol cant anymore viewed in expression blend. Im a little confused because the application anyway started and all is working. Here is a little code of mine.
public partial class _ColorPicker
{
private readonly DependencyProperty IsCurrentColorProperty;public \_ColorPicker() { this.InitializeComponent(); IsCurrentColorProperty = DependencyProperty.Register( "IsCurrentColor", typeof(Color), typeof(\_ColorPicker), new FrameworkPropertyMetadata(Color.FromRgb(255, 255, 255), new PropertyChangedCallback(OnIsCurrentColorChanged))); } private void OnIsCurrentColorChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) { SetColorInfos((Color)e.NewValue); \_currentColor.Background = new SolidColorBrush((Color)e.NewValue); //RaiseEvent(new RoutedEventArgs(this.iCurrentColorChangedEvent, (Color)e.NewValue)); }
}
-
Hello all, Im working on an ColorPicker user control and have problems registering DependencyPropertys. I try to register a new DependencyProperty in Visual Studio 2008 and all is working fine so far. Now i open Expression blend, add an reference to the ColorPicker.dll, and add a new instance to the window. When i now build the solution i get an exeption: "the property IsCurrentColor has allready been registerd from _ColorPicker" and the usercontrol cant anymore viewed in expression blend. Im a little confused because the application anyway started and all is working. Here is a little code of mine.
public partial class _ColorPicker
{
private readonly DependencyProperty IsCurrentColorProperty;public \_ColorPicker() { this.InitializeComponent(); IsCurrentColorProperty = DependencyProperty.Register( "IsCurrentColor", typeof(Color), typeof(\_ColorPicker), new FrameworkPropertyMetadata(Color.FromRgb(255, 255, 255), new PropertyChangedCallback(OnIsCurrentColorChanged))); } private void OnIsCurrentColorChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) { SetColorInfos((Color)e.NewValue); \_currentColor.Background = new SolidColorBrush((Color)e.NewValue); //RaiseEvent(new RoutedEventArgs(this.iCurrentColorChangedEvent, (Color)e.NewValue)); }
}
Dependency properties need to be static, you may want to download some snippets. There are some basic ones built in (Try propdp[TAB]) and a few others from different sources try http://drwpf.com/blog/Home/tabid/36/EntryId/22/Default.aspx.
-
Hello all, Im working on an ColorPicker user control and have problems registering DependencyPropertys. I try to register a new DependencyProperty in Visual Studio 2008 and all is working fine so far. Now i open Expression blend, add an reference to the ColorPicker.dll, and add a new instance to the window. When i now build the solution i get an exeption: "the property IsCurrentColor has allready been registerd from _ColorPicker" and the usercontrol cant anymore viewed in expression blend. Im a little confused because the application anyway started and all is working. Here is a little code of mine.
public partial class _ColorPicker
{
private readonly DependencyProperty IsCurrentColorProperty;public \_ColorPicker() { this.InitializeComponent(); IsCurrentColorProperty = DependencyProperty.Register( "IsCurrentColor", typeof(Color), typeof(\_ColorPicker), new FrameworkPropertyMetadata(Color.FromRgb(255, 255, 255), new PropertyChangedCallback(OnIsCurrentColorChanged))); } private void OnIsCurrentColorChanged(DependencyObject o, DependencyPropertyChangedEventArgs e) { SetColorInfos((Color)e.NewValue); \_currentColor.Background = new SolidColorBrush((Color)e.NewValue); //RaiseEvent(new RoutedEventArgs(this.iCurrentColorChangedEvent, (Color)e.NewValue)); }
}
As Dave said - Dependency Properties need to be static. As well as Dr WPFs snippets, you may want to download MoXAML and install it in Visual Studio. One of the addin commands allows you to add boilerplate dependency properties just by filling in a dialog box. Follow my sig for the addin.
"WPF has many lovers. It's a veritable porn star!" - Josh Smith