ColorEditor.cs 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. using System.Windows;
  2. using System.Windows.Media;
  3. using Xceed.Wpf.Toolkit;
  4. namespace InABox.DynamicGrid
  5. {
  6. public class ColorEditorControl : DynamicEditorControl<string>
  7. {
  8. private ColorPicker Editor;
  9. protected override FrameworkElement CreateEditor()
  10. {
  11. Editor = new ColorPicker
  12. {
  13. HorizontalAlignment = HorizontalAlignment.Stretch,
  14. VerticalAlignment = VerticalAlignment.Stretch,
  15. VerticalContentAlignment = VerticalAlignment.Center
  16. };
  17. Editor.SelectedColorChanged += (o, e) => CheckChanged();
  18. return Editor;
  19. }
  20. public override int DesiredHeight()
  21. {
  22. return 25;
  23. }
  24. public override int DesiredWidth()
  25. {
  26. return 150;
  27. }
  28. protected override string RetrieveValue()
  29. {
  30. return Editor.SelectedColor.HasValue ? Editor.SelectedColor.Value.ToString() : "";
  31. }
  32. protected override void UpdateValue(string value)
  33. {
  34. if (!string.IsNullOrWhiteSpace(value))
  35. Editor.SelectedColor = (Color)ColorConverter.ConvertFromString(value);
  36. else
  37. Editor.SelectedColor = null;
  38. }
  39. public override void SetFocus()
  40. {
  41. Editor.Focus();
  42. }
  43. public override void SetColor(Color color)
  44. {
  45. Editor.Background = new SolidColorBrush(color);
  46. }
  47. }
  48. }