新增实时按钮功能
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace XplorePlane.Controls
|
||||
{
|
||||
public class AnimatedSwitch : ToggleButton
|
||||
{
|
||||
static AnimatedSwitch()
|
||||
{
|
||||
DefaultStyleKeyProperty.OverrideMetadata(
|
||||
typeof(AnimatedSwitch),
|
||||
new FrameworkPropertyMetadata(typeof(AnimatedSwitch)));
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty OnBrushProperty =
|
||||
DependencyProperty.Register(
|
||||
nameof(OnBrush),
|
||||
typeof(Brush),
|
||||
typeof(AnimatedSwitch),
|
||||
new PropertyMetadata(new SolidColorBrush(Color.FromRgb(45, 204, 112))));
|
||||
|
||||
public static readonly DependencyProperty OffBrushProperty =
|
||||
DependencyProperty.Register(
|
||||
nameof(OffBrush),
|
||||
typeof(Brush),
|
||||
typeof(AnimatedSwitch),
|
||||
new PropertyMetadata(new SolidColorBrush(Color.FromRgb(205, 212, 218))));
|
||||
|
||||
public static readonly DependencyProperty ThumbBrushProperty =
|
||||
DependencyProperty.Register(
|
||||
nameof(ThumbBrush),
|
||||
typeof(Brush),
|
||||
typeof(AnimatedSwitch),
|
||||
new PropertyMetadata(Brushes.White));
|
||||
|
||||
public static readonly DependencyProperty SwitchWidthProperty =
|
||||
DependencyProperty.Register(
|
||||
nameof(SwitchWidth),
|
||||
typeof(double),
|
||||
typeof(AnimatedSwitch),
|
||||
new PropertyMetadata(44d));
|
||||
|
||||
public static readonly DependencyProperty SwitchHeightProperty =
|
||||
DependencyProperty.Register(
|
||||
nameof(SwitchHeight),
|
||||
typeof(double),
|
||||
typeof(AnimatedSwitch),
|
||||
new PropertyMetadata(24d));
|
||||
|
||||
public Brush OnBrush
|
||||
{
|
||||
get => (Brush)GetValue(OnBrushProperty);
|
||||
set => SetValue(OnBrushProperty, value);
|
||||
}
|
||||
|
||||
public Brush OffBrush
|
||||
{
|
||||
get => (Brush)GetValue(OffBrushProperty);
|
||||
set => SetValue(OffBrushProperty, value);
|
||||
}
|
||||
|
||||
public Brush ThumbBrush
|
||||
{
|
||||
get => (Brush)GetValue(ThumbBrushProperty);
|
||||
set => SetValue(ThumbBrushProperty, value);
|
||||
}
|
||||
|
||||
public double SwitchWidth
|
||||
{
|
||||
get => (double)GetValue(SwitchWidthProperty);
|
||||
set => SetValue(SwitchWidthProperty, value);
|
||||
}
|
||||
|
||||
public double SwitchHeight
|
||||
{
|
||||
get => (double)GetValue(SwitchHeightProperty);
|
||||
set => SetValue(SwitchHeightProperty, value);
|
||||
}
|
||||
|
||||
protected override void OnPreviewMouseLeftButtonDown(MouseButtonEventArgs e)
|
||||
{
|
||||
if (!IsEnabled)
|
||||
{
|
||||
base.OnPreviewMouseLeftButtonDown(e);
|
||||
return;
|
||||
}
|
||||
|
||||
e.Handled = true;
|
||||
Focus();
|
||||
OnClick();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user