URLEditorControl.cs 2.1 KB

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