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 { /// /// OrderControl.xaml 的交互逻辑 /// public partial class OrderControl : UserControl { public OrderControl() { InitializeComponent(); } public int State { get { return (int)GetValue(StateProperty); } set { SetValue(StateProperty, value); } } // Using a DependencyProperty as the backing store for State. This enables animation, styling, binding, etc... public static readonly DependencyProperty StateProperty = DependencyProperty.Register("State", typeof(int), typeof(OrderControl), new PropertyMetadata(0, new PropertyChangedCallback(StatePropertyChangedCallback))); private static void StatePropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (e.NewValue == null) return; int newValue = int.Parse(e.NewValue.ToString()); var source = (OrderControl)d; switch (newValue) { case 0: source.img_up.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/orderControl_gray_up.png", UriKind.Absolute)); source.img_dwon.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/orderControl_gray_dwon.png", UriKind.Absolute)); break; case 1: source.img_up.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/orderControl_blue_up.png", UriKind.Absolute)); source.img_dwon.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/orderControl_gray_dwon.png", UriKind.Absolute)); break; case 2: source.img_up.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/orderControl_gray_up.png", UriKind.Absolute)); source.img_dwon.Source = new BitmapImage(new Uri("pack://application:,,,/ivf_tl_Manage;component/Resources/Images/orderControl_blue_dwon.png", UriKind.Absolute)); break; default: break; } } public string Text { get { return (string)GetValue(TextProperty); } set { SetValue(TextProperty, value); } } // Using a DependencyProperty as the backing store for TextProperty. This enables animation, styling, binding, etc... public static readonly DependencyProperty TextProperty = DependencyProperty.Register("Text", typeof(string), typeof(OrderControl), new PropertyMetadata(null, new PropertyChangedCallback(TextPropertyChangedCallback))); private static void TextPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { if (e.NewValue == null) return; string newValue = e.NewValue.ToString(); if (string.IsNullOrEmpty(newValue)) return; var source = (OrderControl)d; source.btn_order.Text = newValue; } public bool isSelect { get { return (bool)GetValue(isSelectProperty); } set { SetValue(isSelectProperty, value); } } // Using a DependencyProperty as the backing store for isSelect. This enables animation, styling, binding, etc... public static readonly DependencyProperty isSelectProperty = DependencyProperty.Register("isSelect", typeof(bool), typeof(OrderControl), new PropertyMetadata(false, new PropertyChangedCallback(IsSelectPropertyChangedCallback))); private static void IsSelectPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) { bool? newValue = e.NewValue as bool?; if (newValue == null) return; var source = (OrderControl)d; if (source.isSelect) { source.btn_order.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4D75AC")); } else { source.btn_order.Foreground = new SolidColorBrush((Color)ColorConverter.ConvertFromString("#4D4D4D")); source.State = 0; } } private bool clicktype = true; private void img_dwon_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { clicktype = true; isSelect = true; State = clicktype ? 2 : 1; } private void img_up_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { clicktype = false; isSelect = true; State = clicktype ? 2 : 1; } private void StackPanel_MouseLeftButtonDown(object sender, MouseButtonEventArgs e) { if (e.OriginalSource is not Image) { clicktype = !clicktype; State = clicktype ? 2 : 1; isSelect = true; } } } }