URLEditorControl.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using System.Diagnostics;
  2. using System.Windows;
  3. using System.Windows.Controls;
  4. using System.Windows.Media;
  5. using InABox.Core;
  6. namespace InABox.DynamicGrid
  7. {
  8. public class URLEditorControl : DynamicEditorControl<string, URLEditor>
  9. {
  10. static URLEditorControl()
  11. {
  12. //DynamicEditorControlFactory.Register<URLEditorControl, URLEditor>();
  13. }
  14. private TextBox Editor;
  15. public override void Configure()
  16. {
  17. }
  18. protected override FrameworkElement CreateEditor()
  19. {
  20. var dock = new DockPanel
  21. {
  22. VerticalAlignment = VerticalAlignment.Stretch,
  23. HorizontalAlignment = HorizontalAlignment.Stretch
  24. };
  25. var button = new Button
  26. {
  27. Content = "Go",
  28. VerticalAlignment = VerticalAlignment.Stretch,
  29. VerticalContentAlignment = VerticalAlignment.Center,
  30. Padding = new Thickness(5, 0, 5, 0)
  31. };
  32. button.Click += (o, e) => { Process.Start(new ProcessStartInfo(Editor.Text) { UseShellExecute = true }); };
  33. button.SetValue(DockPanel.DockProperty, Dock.Right);
  34. dock.Children.Add(button);
  35. Editor = new TextBox
  36. {
  37. VerticalAlignment = VerticalAlignment.Stretch,
  38. VerticalContentAlignment = VerticalAlignment.Center,
  39. HorizontalAlignment = HorizontalAlignment.Stretch,
  40. Margin = new Thickness(0, 0, 5, 0)
  41. };
  42. Editor.SetValue(DockPanel.DockProperty, Dock.Left);
  43. Editor.TextChanged += (o, e) => { CheckChanged(); };
  44. dock.Children.Add(Editor);
  45. return dock;
  46. }
  47. public override int DesiredHeight()
  48. {
  49. return 25;
  50. }
  51. public override int DesiredWidth()
  52. {
  53. return int.MaxValue;
  54. }
  55. protected override string RetrieveValue()
  56. {
  57. return Editor.Text;
  58. }
  59. protected override void UpdateValue(string value)
  60. {
  61. Editor.Text = value;
  62. }
  63. public override void SetFocus()
  64. {
  65. Editor.Focus();
  66. }
  67. public override void SetColor(Color color)
  68. {
  69. Editor.Background = new SolidColorBrush(color);
  70. }
  71. }
  72. }