diff --git a/HandyControl/Controls/Attach/LinkElement.cs b/HandyControl/Controls/Attach/LinkElement.cs index 5da5d111..d962952c 100644 --- a/HandyControl/Controls/Attach/LinkElement.cs +++ b/HandyControl/Controls/Attach/LinkElement.cs @@ -14,7 +14,7 @@ namespace HandyControl.Controls { if (d is UIElement element) { - CreateTrriger(element, (string) e.NewValue); + CreateTrigger(element, (string) e.NewValue); } } @@ -27,7 +27,7 @@ namespace HandyControl.Controls private static CommandBinding GetCommandBinding(DependencyObject element) => (CommandBinding) element.GetValue(CommandBindingProperty); - private static void CreateTrriger(UIElement element, string link) + private static void CreateTrigger(UIElement element, string link) { element.CommandBindings.Remove(GetCommandBinding(element)); element.SetCurrentValue(CommandBindingProperty, DependencyProperty.UnsetValue); diff --git a/HandyControl/Controls/Other/CircleProgressBar.cs b/HandyControl/Controls/ProgressBar/CircleProgressBar.cs similarity index 100% rename from HandyControl/Controls/Other/CircleProgressBar.cs rename to HandyControl/Controls/ProgressBar/CircleProgressBar.cs diff --git a/HandyControl/Controls/ProgressBar/WaveProgressBar.cs b/HandyControl/Controls/ProgressBar/WaveProgressBar.cs new file mode 100644 index 00000000..196665ca --- /dev/null +++ b/HandyControl/Controls/ProgressBar/WaveProgressBar.cs @@ -0,0 +1,119 @@ +using System.Windows; +using System.Windows.Controls.Primitives; +using System.Windows.Media; +using HandyControl.Data; +using HandyControl.Expression.Drawing; + +namespace HandyControl.Controls +{ + /// + /// 波浪进度条 + /// + [TemplatePart(Name = ElementWave, Type = typeof(FrameworkElement))] + [TemplatePart(Name = ElementClip, Type = typeof(FrameworkElement))] + public class WaveProgressBar : RangeBase + { + private const string ElementWave = "PART_Wave"; + + private const string ElementClip = "PART_Clip"; + + private FrameworkElement _waveElement; + + private const double TranslateTransformMinY = -20; + + private double _translateTransformYRange; + + private TranslateTransform _translateTransform; + + public WaveProgressBar() => Loaded += (s, e) => UpdateWave(Value); + + static WaveProgressBar() + { + FocusableProperty.OverrideMetadata(typeof(WaveProgressBar), + new FrameworkPropertyMetadata(ValueBoxes.FalseBox)); + MaximumProperty.OverrideMetadata(typeof(WaveProgressBar), + new FrameworkPropertyMetadata(ValueBoxes.Double100Box)); + } + + protected override void OnValueChanged(double oldValue, double newValue) + { + base.OnValueChanged(oldValue, newValue); + + UpdateWave(newValue); + } + + private void UpdateWave(double value) + { + if (_translateTransform == null || MathHelper.IsVerySmall(Maximum)) return; + var scale = 1 - value / Maximum; + var y = _translateTransformYRange * scale + TranslateTransformMinY; + _translateTransform.Y = y; + } + + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + + _waveElement = GetTemplateChild(ElementWave) as FrameworkElement; + var clipElement = GetTemplateChild(ElementClip) as FrameworkElement; + + if (_waveElement != null && clipElement != null) + { + _translateTransform = new TranslateTransform + { + Y = clipElement.Height + }; + _translateTransformYRange = clipElement.Height - TranslateTransformMinY; + _waveElement.RenderTransform = new TransformGroup + { + Children = {_translateTransform} + }; + } + } + + public static readonly DependencyProperty TextProperty = DependencyProperty.Register( + "Text", typeof(string), typeof(WaveProgressBar), new PropertyMetadata(default(string))); + + public string Text + { + get => (string)GetValue(TextProperty); + set => SetValue(TextProperty, value); + } + + public static readonly DependencyProperty ShowTextProperty = DependencyProperty.Register( + "ShowText", typeof(bool), typeof(WaveProgressBar), new PropertyMetadata(ValueBoxes.TrueBox)); + + public bool ShowText + { + get => (bool)GetValue(ShowTextProperty); + set => SetValue(ShowTextProperty, value); + } + + public static readonly DependencyProperty WaveFillProperty = DependencyProperty.Register( + "WaveFill", typeof(Brush), typeof(WaveProgressBar), new PropertyMetadata(default(Brush))); + + public Brush WaveFill + { + get => (Brush) GetValue(WaveFillProperty); + set => SetValue(WaveFillProperty, value); + } + + public static readonly DependencyProperty WaveThicknessProperty = DependencyProperty.Register( + "WaveThickness", typeof(double), typeof(WaveProgressBar), new PropertyMetadata(ValueBoxes.Double0Box)); + + public double WaveThickness + { + get => (double) GetValue(WaveThicknessProperty); + set => SetValue(WaveThicknessProperty, value); + } + + public static readonly DependencyProperty WaveStrokeProperty = DependencyProperty.Register( + "WaveStroke", typeof(Brush), typeof(WaveProgressBar), new PropertyMetadata(default(Brush))); + + public Brush WaveStroke + { + get => (Brush) GetValue(WaveStrokeProperty); + set => SetValue(WaveStrokeProperty, value); + } + } +} \ No newline at end of file diff --git a/HandyControl/HandyControl.csproj b/HandyControl/HandyControl.csproj index 6e20ed86..a01d6620 100644 --- a/HandyControl/HandyControl.csproj +++ b/HandyControl/HandyControl.csproj @@ -117,11 +117,12 @@ + - + diff --git a/HandyControl/Themes/Styles/Base/ProgressBarBaseStyle.xaml b/HandyControl/Themes/Styles/Base/ProgressBarBaseStyle.xaml index df26dbfe..e6279918 100644 --- a/HandyControl/Themes/Styles/Base/ProgressBarBaseStyle.xaml +++ b/HandyControl/Themes/Styles/Base/ProgressBarBaseStyle.xaml @@ -5,6 +5,7 @@ + @@ -70,13 +71,12 @@ + + \ No newline at end of file diff --git a/HandyControl/Themes/Styles/ProgressBar.xaml b/HandyControl/Themes/Styles/ProgressBar.xaml index ce272123..117fc66b 100644 --- a/HandyControl/Themes/Styles/ProgressBar.xaml +++ b/HandyControl/Themes/Styles/ProgressBar.xaml @@ -196,6 +196,26 @@ + + + + + + + + + +