| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293 |
- 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_Operate.CustomUserControls
- {
- /// <summary>
- /// ChartButton.xaml 的交互逻辑
- /// </summary>
- public partial class ChartButton : UserControl
- {
- public ChartButton()
- {
- InitializeComponent();
- }
- /// <summary>
- /// 按钮内容
- /// </summary>
- public new string Content
- {
- get { return (string)GetValue(ContentProperty); }
- set { SetValue(ContentProperty, value); }
- }
- public static new readonly DependencyProperty ContentProperty =
- DependencyProperty.Register("Content", typeof(string), typeof(ChartButton), new PropertyMetadata("0", new PropertyChangedCallback(OnContentPropertyChangedCallback)));
- private static void OnContentPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (!(d is ChartButton source)) return;
- if (!(e.NewValue is string content)) return;
- source._content.Text = content;
- }
- /// <summary>
- /// 是否选中
- /// </summary>
- public bool IsSelected
- {
- get { return (bool)GetValue(IsSelectedProperty); }
- set { SetValue(IsSelectedProperty, value); }
- }
- public static readonly DependencyProperty IsSelectedProperty =
- DependencyProperty.Register("IsSelected", typeof(bool), typeof(ChartButton), new PropertyMetadata(false, new PropertyChangedCallback(OnIsSelectedPropertyChangedCallback)));
- private static void OnIsSelectedPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (!(d is ChartButton source)) return;
- if (!(e.NewValue is bool selected)) return;
- if (selected)
- {
- source._img.Visibility = Visibility.Visible;
- source._content.Foreground = new SolidColorBrush(Color.FromRgb(255, 255, 255));//白色
- }
- else
- {
- source._img.Visibility = Visibility.Hidden;
- source._content.Foreground = new SolidColorBrush(Color.FromRgb(110, 114, 118));//灰色
- }
- }
- public Brush TextForeground
- {
- get { return (Brush)GetValue(TextForegroundProperty); }
- set { SetValue(TextForegroundProperty, value); }
- }
- public static readonly DependencyProperty TextForegroundProperty =
- DependencyProperty.Register("TextForeground", typeof(Brush), typeof(ChartButton), new PropertyMetadata(new SolidColorBrush(Color.FromRgb(110, 114, 118)), new PropertyChangedCallback(OnForegroundPropertyChangedCallback)));
- private static void OnForegroundPropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (!(d is ChartButton source)) return;
- if (!(e.NewValue is Brush newBrush)) return;
- source._content.Foreground = newBrush;
- }
- }
- }
|