I’m working with the WPF Extended Toolkit’s Property Editor, and I need to add support for editing System.Drawing.Color using the color editor that comes with this Toolkit.
The current color editor does its job via a Color Picker component, and seems to use data binding to wire up the Color Picker’s SelectedColor property directly to the edited object’s color property. Unfortunately the Toolkit’s editors are implemented by returning a DependencyProperty to bind to, rather than by being asked to bind it themselves, so it doesn’t seem I can insert the (absolutely trivial) type conversion there.
I see only two other ways of doing this:
- duplicate the entire Color Picker, changing the type of the property it edits. This is the last thing I want to do for obvious reasons.
- expose a second Color property from the Color Picker, of the type
System.Drawing.Color, so that my new color editor can tell the property grid to bind to that one. But I’ve been told that having two dependency properties with the same underlying value is a terrible idea.
Is there a better way?
If I really should expose two kinds of Color properties in the Color Picker component, what’s the correct way to keep them “in sync”?
You can data bind to a
System.Drawing.Colorusing a value converter. This works in my test environment.The XAML:
code for the test view model: