1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556 |
- using System.Windows;
- using System.Windows.Media;
- using Xceed.Wpf.Toolkit;
- namespace InABox.DynamicGrid
- {
- public class ColorEditorControl : DynamicEditorControl<string>
- {
- private ColorPicker Editor;
- protected override FrameworkElement CreateEditor()
- {
- Editor = new ColorPicker
- {
- HorizontalAlignment = HorizontalAlignment.Stretch,
- VerticalAlignment = VerticalAlignment.Stretch,
- VerticalContentAlignment = VerticalAlignment.Center
- };
- Editor.SelectedColorChanged += (o, e) => CheckChanged();
- return Editor;
- }
- public override int DesiredHeight()
- {
- return 25;
- }
- public override int DesiredWidth()
- {
- return 150;
- }
- protected override string RetrieveValue()
- {
- return Editor.SelectedColor.HasValue ? Editor.SelectedColor.Value.ToString() : "";
- }
- protected override void UpdateValue(string value)
- {
- if (!string.IsNullOrWhiteSpace(value))
- Editor.SelectedColor = (Color)ColorConverter.ConvertFromString(value);
- else
- Editor.SelectedColor = null;
- }
- public override void SetFocus()
- {
- Editor.Focus();
- }
- public override void SetColor(Color color)
- {
- Editor.Background = new SolidColorBrush(color);
- }
- }
- }
|