123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108 |
- using System;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Media;
- using Xceed.Wpf.Toolkit;
- namespace InABox.DynamicGrid
- {
- public class TimestampEditorControl : DynamicEditorControl<DateTime>
- {
- private Button Button;
- private DateTimePicker Editor;
- protected override FrameworkElement CreateEditor()
- {
- var DockPanel = new DockPanel
- {
- HorizontalAlignment = HorizontalAlignment.Stretch
- };
- Editor = new DateTimePicker
- {
- Format = DateTimeFormat.Custom,
- FormatString = "dd MMM yyyy HH:mm:ss",
- HorizontalAlignment = HorizontalAlignment.Left,
- VerticalAlignment = VerticalAlignment.Stretch,
- VerticalContentAlignment = VerticalAlignment.Center,
- HorizontalContentAlignment = HorizontalAlignment.Center,
- ShowButtonSpinner = false,
- //ShowDropDownButton = false,
- Focusable = false,
- IsReadOnly = true,
- Background = new SolidColorBrush(Colors.Gainsboro),
- Width = 150
- };
- Editor.SetValue(DockPanel.DockProperty, Dock.Left);
- Editor.ValueChanged += (o, e) => CheckChanged();
- Button = new Button
- {
- Content = "Set",
- Width = 45,
- Margin = new Thickness(5, 0, 0, 0),
- Focusable = true
- };
- Button.SetValue(DockPanel.DockProperty, Dock.Right);
- Button.Click += ButtonClick;
- DockPanel.Children.Add(Button);
- DockPanel.Children.Add(Editor);
- return DockPanel;
- }
- private void ButtonClick(object sender, RoutedEventArgs e)
- {
- if (((string)Button.Content).Equals("Set"))
- Editor.Value = DateTime.Now;
- else
- Editor.Value = null;
- Button.Content = Editor.Value.HasValue ? "Clear" : "Set";
- }
- public override int DesiredHeight()
- {
- return 25;
- }
- public override int DesiredWidth()
- {
- return 150 + (int)Button.Width + 5;
- }
- protected override DateTime RetrieveValue()
- {
- if (Editor.Value.HasValue)
- return Editor.Value.Value;
- return DateTime.MinValue;
- }
- protected override void UpdateValue(DateTime value)
- {
- if (value != DateTime.MinValue)
- {
- Editor.Value = value;
- Button.Content = "Clear"; // Editor.Value.Equals(DateTime.MinValue) ? "Set" : "Clear";
- }
- else
- {
- Editor.Value = null;
- Button.Content = "Set";
- }
- }
- public override void SetFocus()
- {
- Button.Focus();
- }
- public override void SetColor(Color color)
- {
- //Editor.Background = new SolidColorBrush(color);
- }
- }
- }
|