diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/CircleProgressBarExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/CircleProgressBarExample.xaml new file mode 100644 index 00000000..c7a319e3 --- /dev/null +++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/CircleProgressBarExample.xaml @@ -0,0 +1,61 @@ + + + + + + + + + + + + + + + + + diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/CircleProgressBarExample.xaml.cs b/src/WPFDevelopers.Samples.Shared/ExampleViews/CircleProgressBarExample.xaml.cs new file mode 100644 index 00000000..c6b6ca8b --- /dev/null +++ b/src/WPFDevelopers.Samples.Shared/ExampleViews/CircleProgressBarExample.xaml.cs @@ -0,0 +1,15 @@ +using System.Windows.Controls; + +namespace WPFDevelopers.Samples.ExampleViews +{ + /// + /// CircleProgressBarExample.xaml 的交互逻辑 + /// + public partial class CircleProgressBarExample : UserControl + { + public CircleProgressBarExample() + { + InitializeComponent(); + } + } +} diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/CircularProgressBarExample.xaml b/src/WPFDevelopers.Samples.Shared/ExampleViews/CircularProgressBarExample.xaml deleted file mode 100644 index 7b8f195d..00000000 --- a/src/WPFDevelopers.Samples.Shared/ExampleViews/CircularProgressBarExample.xaml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - - - - - - - - - - - diff --git a/src/WPFDevelopers.Samples.Shared/ExampleViews/CircularProgressBarExample.xaml.cs b/src/WPFDevelopers.Samples.Shared/ExampleViews/CircularProgressBarExample.xaml.cs deleted file mode 100644 index d329787b..00000000 --- a/src/WPFDevelopers.Samples.Shared/ExampleViews/CircularProgressBarExample.xaml.cs +++ /dev/null @@ -1,27 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -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 WPFDevelopers.Samples.ExampleViews -{ - /// - /// CircularProgressBarExample.xaml 的交互逻辑 - /// - public partial class CircularProgressBarExample : UserControl - { - public CircularProgressBarExample() - { - InitializeComponent(); - } - } -} diff --git a/src/WPFDevelopers.Samples.Shared/Helpers/MenuEnum.cs b/src/WPFDevelopers.Samples.Shared/Helpers/MenuEnum.cs index 0bcc0183..68a18aba 100644 --- a/src/WPFDevelopers.Samples.Shared/Helpers/MenuEnum.cs +++ b/src/WPFDevelopers.Samples.Shared/Helpers/MenuEnum.cs @@ -24,7 +24,7 @@ public enum MenuEnum VerifyCode, CircleMenu, ChatEmoji, - ProgressBar, + CircleProgressBar, Dashboard, PieControl, Password, diff --git a/src/WPFDevelopers.Samples.Shared/ViewModels/MainVM.cs b/src/WPFDevelopers.Samples.Shared/ViewModels/MainVM.cs index 1502bd45..d003502e 100644 --- a/src/WPFDevelopers.Samples.Shared/ViewModels/MainVM.cs +++ b/src/WPFDevelopers.Samples.Shared/ViewModels/MainVM.cs @@ -170,8 +170,8 @@ void MenuItemSelection(string _menuName) case MenuEnum.ChatEmoji: ControlPanel = new ChatEmojiExample(); break; - case MenuEnum.ProgressBar: - ControlPanel = new CircularProgressBarExample(); + case MenuEnum.CircleProgressBar: + ControlPanel = new CircleProgressBarExample(); break; case MenuEnum.Dashboard: ControlPanel = new DashboardExample(); diff --git a/src/WPFDevelopers.Samples.Shared/WPFDevelopers.Samples.Shared.projitems b/src/WPFDevelopers.Samples.Shared/WPFDevelopers.Samples.Shared.projitems index 6e6d917f..7771ddc7 100644 --- a/src/WPFDevelopers.Samples.Shared/WPFDevelopers.Samples.Shared.projitems +++ b/src/WPFDevelopers.Samples.Shared/WPFDevelopers.Samples.Shared.projitems @@ -119,9 +119,9 @@ Code CircleMenuExample.xaml - + Code - CircularProgressBarExample.xaml + CircleProgressBarExample.xaml ColorPickerExample.xaml @@ -616,7 +616,7 @@ MSBuild:Compile Designer - + MSBuild:Compile Designer diff --git a/src/WPFDevelopers.SamplesCode/WPFDevelopers.SamplesCode.csproj b/src/WPFDevelopers.SamplesCode/WPFDevelopers.SamplesCode.csproj index cfa41218..308f7d07 100644 --- a/src/WPFDevelopers.SamplesCode/WPFDevelopers.SamplesCode.csproj +++ b/src/WPFDevelopers.SamplesCode/WPFDevelopers.SamplesCode.csproj @@ -194,8 +194,8 @@ ExampleViews\CircularMenuExample.xaml - - ExampleViews\CircularProgressBarExample.xaml + + ExampleViews\CircleProgressBarExample.xaml ExampleViews\CountdownTimerExample.xaml diff --git a/src/WPFDevelopers.Shared/Controls/CircularProgressBar/CircularProgressBar.cs b/src/WPFDevelopers.Shared/Controls/CircleProgressBar/CircleProgressBar.cs similarity index 70% rename from src/WPFDevelopers.Shared/Controls/CircularProgressBar/CircularProgressBar.cs rename to src/WPFDevelopers.Shared/Controls/CircleProgressBar/CircleProgressBar.cs index c13c49cb..c3391d4d 100644 --- a/src/WPFDevelopers.Shared/Controls/CircularProgressBar/CircularProgressBar.cs +++ b/src/WPFDevelopers.Shared/Controls/CircleProgressBar/CircleProgressBar.cs @@ -11,73 +11,63 @@ namespace WPFDevelopers.Controls [TemplatePart(Name = PathFigureTemplateName, Type = typeof(PathFigure))] [TemplatePart(Name = PathFigureAngleTemplateName, Type = typeof(PathFigure))] [TemplatePart(Name = TextBlockTemplateName, Type = typeof(TextBlock))] - public class CircularProgressBar : ProgressBar + public class CircleProgressBar : ProgressBar { private const string ArcSegmentTemplateName = "PART_ArcSegment"; private const string ArcSegmentAngleTemplateName = "PART_ArcSegmentAngle"; private const string PathFigureTemplateName = "PART_PathFigure"; private const string PathFigureAngleTemplateName = "PART_PathFigureAngle"; private const string TextBlockTemplateName = "PART_TextBlock"; + private readonly Size _size = new Size(50,50); private ArcSegment _arcSegment, _arcSegmentAngle; private PathFigure _pathFigure, _pathFigureAngle; private TextBlock _textBlock; + public static readonly DependencyProperty IsRoundProperty = + DependencyProperty.Register("IsRound", typeof(bool), typeof(CircleProgressBar), + new PropertyMetadata(false)); - public static readonly DependencyProperty SizeProperty = - DependencyProperty.Register("Size", typeof(Size), typeof(CircularProgressBar), - new PropertyMetadata(new Size(50,50))); public static readonly DependencyProperty AngleProperty = - DependencyProperty.Register("Angle", typeof(double), typeof(CircularProgressBar), + DependencyProperty.Register("Angle", typeof(double), typeof(CircleProgressBar), new PropertyMetadata(0.0)); public static readonly DependencyProperty StrokeThicknessProperty = - DependencyProperty.Register("StrokeThickness", typeof(double), typeof(CircularProgressBar), - new PropertyMetadata(10.0)); + DependencyProperty.Register("StrokeThickness", typeof(double), typeof(CircleProgressBar), + new PropertyMetadata(5.0)); public static readonly DependencyProperty BrushStrokeThicknessProperty = - DependencyProperty.Register("BrushStrokeThickness", typeof(double), typeof(CircularProgressBar), - new PropertyMetadata(1.0)); + DependencyProperty.Register("BrushStrokeThickness", typeof(double), typeof(CircleProgressBar), + new PropertyMetadata(5.0)); - public CircularProgressBar() + public CircleProgressBar() { ValueChanged += CircularProgressBar_ValueChanged; } public override void OnApplyTemplate() { base.OnApplyTemplate(); - - if (Size.Width != Size.Height) - { - var max = Math.Max(Size.Width, Size.Height); - Size = new Size(max, max); - } - _pathFigure = GetTemplateChild(PathFigureTemplateName) as PathFigure; _pathFigureAngle = GetTemplateChild(PathFigureAngleTemplateName) as PathFigure; - _pathFigure.StartPoint = new Point(Size.Width, 0); - _pathFigureAngle.StartPoint = new Point(Size.Width, 0); + _pathFigure.StartPoint = new Point(_size.Width, 0); + _pathFigureAngle.StartPoint = new Point(_size.Width, 0); _arcSegment = GetTemplateChild(ArcSegmentTemplateName) as ArcSegment; - _arcSegment.Size = Size; - _arcSegment.Point = new Point(Size.Width - 0.000872664626, 7.61543361704753E-09); + _arcSegment.Size = _size; + _arcSegment.Point = new Point(_size.Width - 0.000872664626, 7.61543361704753E-09); _arcSegmentAngle = GetTemplateChild(ArcSegmentAngleTemplateName) as ArcSegment; - _arcSegmentAngle.Size = Size; + _arcSegmentAngle.Size = _size; _textBlock = GetTemplateChild(TextBlockTemplateName) as TextBlock; - if (Size.Width < 15) - { - FontSize = 8; - } } - - public Size Size + + public bool IsRound { - get => (Size)GetValue(SizeProperty); - set => SetValue(SizeProperty, value); + get => (bool)GetValue(IsRoundProperty); + set => SetValue(IsRoundProperty, value); } public double Angle { get => (double)GetValue(AngleProperty); - set => SetValue(AngleProperty, value); + private set => SetValue(AngleProperty, value); } public double StrokeThickness @@ -94,7 +84,7 @@ public double BrushStrokeThickness private void CircularProgressBar_ValueChanged(object sender, RoutedPropertyChangedEventArgs e) { - var bar = sender as CircularProgressBar; + var bar = sender as CircleProgressBar; var currentAngle = bar.Angle; var targetAngle = e.NewValue / bar.Maximum * 359.999; var anim = new DoubleAnimation(currentAngle, targetAngle, TimeSpan.FromMilliseconds(500)); diff --git a/src/WPFDevelopers.Shared/Themes/Basic/Colors.xaml b/src/WPFDevelopers.Shared/Themes/Basic/Colors.xaml index e1f44c5d..024691cb 100644 --- a/src/WPFDevelopers.Shared/Themes/Basic/Colors.xaml +++ b/src/WPFDevelopers.Shared/Themes/Basic/Colors.xaml @@ -28,6 +28,12 @@ x:Key="WD.NormalSolidColorBrush" po:Freeze="True" Color="{StaticResource WD.NormalColor}" /> + #FF13CE67 + + #99FA68 diff --git a/src/WPFDevelopers.Shared/Themes/CircleProgressBar.xaml b/src/WPFDevelopers.Shared/Themes/CircleProgressBar.xaml new file mode 100644 index 00000000..4b4037bb --- /dev/null +++ b/src/WPFDevelopers.Shared/Themes/CircleProgressBar.xaml @@ -0,0 +1,132 @@ + + + + + + + + + -