DynamicFormDesignLength.xaml.cs 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using InABox.Wpf;
  2. using System.Collections.Generic;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. namespace InABox.DynamicGrid
  6. {
  7. /// <summary>
  8. /// Interaction logic for FormDesignerLength.xaml
  9. /// </summary>
  10. public partial class DynamicFormDesignLength : ThemableWindow
  11. {
  12. private readonly Dictionary<GridUnitType, string> types = new()
  13. {
  14. { GridUnitType.Auto, "Auto" },
  15. { GridUnitType.Pixel, "Pixels" },
  16. { GridUnitType.Star, "Percentage" }
  17. };
  18. public DynamicFormDesignLength(GridLength length)
  19. {
  20. InitializeComponent();
  21. Type.ItemsSource = types;
  22. GridLength = length;
  23. }
  24. public GridLength GridLength
  25. {
  26. get => new(Value.Value.Value, (GridUnitType)Type.SelectedValue);
  27. set
  28. {
  29. Type.SelectedValue = value.GridUnitType;
  30. Value.Value = value.Value;
  31. }
  32. }
  33. private void OKClick(object sender, RoutedEventArgs e)
  34. {
  35. DialogResult = true;
  36. }
  37. private void CancelClick(object sender, RoutedEventArgs e)
  38. {
  39. DialogResult = true;
  40. }
  41. private void Type_SelectionChanged(object sender, SelectionChangedEventArgs e)
  42. {
  43. var newvalue = e.AddedItems.Count > 0 ? ((KeyValuePair<GridUnitType, string>)e.AddedItems[0]).Key : GridUnitType.Auto;
  44. //var oldvalue = e.RemovedItems.Count > 0 ? ((KeyValuePair<GridUnitType, String>)e.RemovedItems[0]).Key : GridUnitType.Auto;
  45. if (newvalue == GridUnitType.Star)
  46. {
  47. Value.Value = 1.0F;
  48. Value.IsReadOnly = false;
  49. }
  50. else if (newvalue == GridUnitType.Auto)
  51. {
  52. Value.Value = 1.0F;
  53. Value.IsReadOnly = true;
  54. }
  55. else if (newvalue == GridUnitType.Pixel)
  56. {
  57. Value.Value = 50.0F;
  58. Value.IsReadOnly = false;
  59. }
  60. }
  61. }
  62. }