DateItem.xaml.cs 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. /// DateItem.xaml 的交互逻辑
  19. /// </summary>
  20. public partial class DateItem : UserControl
  21. {
  22. public Action clickAction;
  23. public DateItem()
  24. {
  25. InitializeComponent();
  26. }
  27. public bool IsSelectProperty
  28. {
  29. get { return (bool)GetValue(IsSelectPropertyProperty); }
  30. set { SetValue(IsSelectPropertyProperty, value); }
  31. }
  32. // Using a DependencyProperty as the backing store for IsSelectProperty. This enables animation, styling, binding, etc...
  33. public static readonly DependencyProperty IsSelectPropertyProperty =
  34. DependencyProperty.Register("IsSelectProperty", typeof(bool), typeof(DateItem), new PropertyMetadata(false,new PropertyChangedCallback(OnIsSelectProertyChangeCallback)));
  35. private static void OnIsSelectProertyChangeCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  36. {
  37. if (!(d is DateItem source)) return;
  38. bool newValue = (bool)e.NewValue;
  39. if (newValue)
  40. source.SetBg();
  41. }
  42. public DateItemData DataItemProperty
  43. {
  44. get { return (DateItemData)GetValue(DataItemPropertyProperty); }
  45. set { SetValue(DataItemPropertyProperty, value); }
  46. }
  47. // Using a DependencyProperty as the backing store for DataItemProperty. This enables animation, styling, binding, etc...
  48. public static readonly DependencyProperty DataItemPropertyProperty =
  49. DependencyProperty.Register("DataItemProperty", typeof(DateItemData), typeof(DateItem), new PropertyMetadata(null, new PropertyChangedCallback(OnDataItemPropertyChangedCallback)));
  50. private static void OnDataItemPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
  51. {
  52. if (!(d is DateItem source)) return;
  53. DateItemData dataItme = (DateItemData)e.NewValue;
  54. if (dataItme == null) return;
  55. source.tx_text.Text = dataItme.Time.Day.ToString();
  56. if (!dataItme.IsCurrentMonth)
  57. {
  58. source.tx_text.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#9B9B9B"));
  59. }
  60. //if (source.CheckToday(dataItme.Time))
  61. //{
  62. // source.bg.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4D75AC"));
  63. // source.tx_text.Foreground=new SolidColorBrush(Colors.White);
  64. //}
  65. }
  66. private void Grid_MouseEnter(object sender, MouseEventArgs e)
  67. {
  68. if (IsSelectProperty)
  69. {
  70. ellipse.Visibility = Visibility.Visible;
  71. }
  72. else
  73. {
  74. bg.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#D4DCE7"));
  75. }
  76. }
  77. private void Grid_MouseLeave(object sender, MouseEventArgs e)
  78. {
  79. if (IsSelectProperty)
  80. {
  81. ellipse.Visibility = Visibility.Collapsed;
  82. }
  83. else
  84. {
  85. bg.Fill = new SolidColorBrush(Colors.Transparent);
  86. }
  87. }
  88. private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
  89. {
  90. IsSelectProperty = true;
  91. clickAction?.Invoke();
  92. }
  93. public void SetBg()
  94. {
  95. bg.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4D75AC"));
  96. tx_text.Foreground = new SolidColorBrush(Colors.White);
  97. }
  98. public void SetTodayBg()
  99. {
  100. if(DataItemProperty.IsToday )
  101. bg.StrokeThickness = 1;
  102. else
  103. bg.StrokeThickness = 0;
  104. }
  105. }
  106. public class DateItemData
  107. {
  108. public DateTime Time { get; set; }
  109. public bool IsCurrentMonth { get; set; }
  110. public bool IsSelect { get; set; }
  111. public bool IsToday { get; set; }
  112. }
  113. }