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
{
///
/// ChartButton.xaml 的交互逻辑
///
public partial class ChartButton : UserControl
{
public ChartButton()
{
InitializeComponent();
}
///
/// 按钮内容
///
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;
}
///
/// 是否选中
///
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;
}
}
}