| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows;
- using System.Windows.Controls;
- using System.Windows.Data;
- using System.Windows.Documents;
- using System.Windows.Input;
- using System.Windows.Media;
- using System.Windows.Media.Imaging;
- using System.Windows.Navigation;
- using System.Windows.Shapes;
- namespace ivf_tl_Manage.UserControls
- {
- /// <summary>
- /// DateItem.xaml 的交互逻辑
- /// </summary>
- public partial class DateItem : UserControl
- {
- public Action clickAction;
- public DateItem()
- {
- InitializeComponent();
- }
- public bool IsSelectProperty
- {
- get { return (bool)GetValue(IsSelectPropertyProperty); }
- set { SetValue(IsSelectPropertyProperty, value); }
- }
- // Using a DependencyProperty as the backing store for IsSelectProperty. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty IsSelectPropertyProperty =
- DependencyProperty.Register("IsSelectProperty", typeof(bool), typeof(DateItem), new PropertyMetadata(false,new PropertyChangedCallback(OnIsSelectProertyChangeCallback)));
- private static void OnIsSelectProertyChangeCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (!(d is DateItem source)) return;
- bool newValue = (bool)e.NewValue;
- if (newValue)
- source.SetBg();
- }
- public DateItemData DataItemProperty
- {
- get { return (DateItemData)GetValue(DataItemPropertyProperty); }
- set { SetValue(DataItemPropertyProperty, value); }
- }
- // Using a DependencyProperty as the backing store for DataItemProperty. This enables animation, styling, binding, etc...
- public static readonly DependencyProperty DataItemPropertyProperty =
- DependencyProperty.Register("DataItemProperty", typeof(DateItemData), typeof(DateItem), new PropertyMetadata(null, new PropertyChangedCallback(OnDataItemPropertyChangedCallback)));
- private static void OnDataItemPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (!(d is DateItem source)) return;
- DateItemData dataItme = (DateItemData)e.NewValue;
- if (dataItme == null) return;
- source.tx_text.Text = dataItme.Time.Day.ToString();
- if (!dataItme.IsCurrentMonth)
- {
- source.tx_text.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#9B9B9B"));
- }
- //if (source.CheckToday(dataItme.Time))
- //{
- // source.bg.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4D75AC"));
- // source.tx_text.Foreground=new SolidColorBrush(Colors.White);
- //}
- }
- private void Grid_MouseEnter(object sender, MouseEventArgs e)
- {
- if (IsSelectProperty)
- {
- ellipse.Visibility = Visibility.Visible;
- }
- else
- {
- bg.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#D4DCE7"));
- }
- }
- private void Grid_MouseLeave(object sender, MouseEventArgs e)
- {
- if (IsSelectProperty)
- {
- ellipse.Visibility = Visibility.Collapsed;
- }
- else
- {
- bg.Fill = new SolidColorBrush(Colors.Transparent);
- }
- }
- private void Grid_MouseDown(object sender, MouseButtonEventArgs e)
- {
- IsSelectProperty = true;
- clickAction?.Invoke();
- }
- public void SetBg()
- {
- bg.Fill = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4D75AC"));
- tx_text.Foreground = new SolidColorBrush(Colors.White);
- }
- public void SetTodayBg()
- {
- if(DataItemProperty.IsToday )
- bg.StrokeThickness = 1;
- else
- bg.StrokeThickness = 0;
- }
- }
- public class DateItemData
- {
- public DateTime Time { get; set; }
- public bool IsCurrentMonth { get; set; }
- public bool IsSelect { get; set; }
- public bool IsToday { get; set; }
- }
- }
|