OrderControl.xaml.cs 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Data;
  9. using System.Windows.Documents;
  10. using System.Windows.Input;
  11. using System.Windows.Media;
  12. using System.Windows.Media.Imaging;
  13. using System.Windows.Navigation;
  14. using System.Windows.Shapes;
  15. namespace ivf_tl_Manage.UserControls
  16. {
  17. /// <summary>
  18. /// OrderControl.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class OrderControl : UserControl
  21. {
  22. public OrderControl()
  23. {
  24. InitializeComponent();
  25. }
  26. public int State
  27. {
  28. get { return (int)GetValue(StateProperty); }
  29. set { SetValue(StateProperty, value); }
  30. }
  31. // Using a DependencyProperty as the backing store for State. This enables animation, styling, binding, etc...
  32. public static readonly DependencyProperty StateProperty =
  33. DependencyProperty.Register("State", typeof(int), typeof(OrderControl), new PropertyMetadata(0, new PropertyChangedCallback(StatePropertyChangedCallback)));
  34. private static void StatePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  35. {
  36. if (e.NewValue == null)
  37. return;
  38. int newValue = int.Parse(e.NewValue.ToString());
  39. var source = (OrderControl)d;
  40. switch (newValue)
  41. {
  42. case 0:
  43. source.img_up.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/orderControl_gray_up.png", UriKind.Absolute));
  44. source.img_dwon.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/orderControl_gray_dwon.png", UriKind.Absolute));
  45. break;
  46. case 1:
  47. source.img_up.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/orderControl_blue_up.png", UriKind.Absolute));
  48. source.img_dwon.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/orderControl_gray_dwon.png", UriKind.Absolute));
  49. break;
  50. case 2:
  51. source.img_up.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/orderControl_gray_up.png", UriKind.Absolute));
  52. source.img_dwon.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/orderControl_blue_dwon.png", UriKind.Absolute));
  53. break;
  54. default:
  55. break;
  56. }
  57. }
  58. public string Text
  59. {
  60. get { return (string)GetValue(TextProperty); }
  61. set { SetValue(TextProperty, value); }
  62. }
  63. // Using a DependencyProperty as the backing store for TextProperty. This enables animation, styling, binding, etc...
  64. public static readonly DependencyProperty TextProperty =
  65. DependencyProperty.Register("Text", typeof(string), typeof(OrderControl), new PropertyMetadata(null, new PropertyChangedCallback(TextPropertyChangedCallback)));
  66. private static void TextPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  67. {
  68. if (e.NewValue == null) return;
  69. string newValue = e.NewValue.ToString();
  70. if (string.IsNullOrEmpty(newValue)) return;
  71. var source = (OrderControl)d;
  72. source.btn_order.Text = newValue;
  73. }
  74. public bool isSelect
  75. {
  76. get { return (bool)GetValue(isSelectProperty); }
  77. set { SetValue(isSelectProperty, value); }
  78. }
  79. // Using a DependencyProperty as the backing store for isSelect. This enables animation, styling, binding, etc...
  80. public static readonly DependencyProperty isSelectProperty =
  81. DependencyProperty.Register("isSelect", typeof(bool), typeof(OrderControl), new PropertyMetadata(false, new PropertyChangedCallback(IsSelectPropertyChangedCallback)));
  82. private static void IsSelectPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  83. {
  84. bool? newValue = e.NewValue as bool?;
  85. if (newValue == null)
  86. return;
  87. var source = (OrderControl)d;
  88. if (source.isSelect)
  89. {
  90. source.btn_order.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4D75AC"));
  91. }
  92. else
  93. {
  94. source.btn_order.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4D4D4D"));
  95. source.State = 0;
  96. }
  97. }
  98. private bool clicktype = true;
  99. private void img_dwon_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  100. {
  101. clicktype = true;
  102. isSelect = true;
  103. State = clicktype ? 2 : 1;
  104. }
  105. private void img_up_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  106. {
  107. clicktype = false;
  108. isSelect = true;
  109. State = clicktype ? 2 : 1;
  110. }
  111. private void StackPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
  112. {
  113. if (e.OriginalSource is not Image)
  114. {
  115. clicktype = !clicktype;
  116. State = clicktype ? 2 : 1;
  117. isSelect = true;
  118. }
  119. }
  120. }
  121. }