From f5eff75421951b10614766056142be7883569e89 Mon Sep 17 00:00:00 2001 From: Russell Camo <32549126+russkyc@users.noreply.github.com> Date: Mon, 16 Oct 2023 15:17:44 +0800 Subject: [PATCH] feat: add linear modern progressbar, partially implements #25 --- .../Controls/ModernProgressbar.cs | 12 ++++ .../Converters/OrientationToAngleConverter.cs | 64 +++++++++++++++++++ .../Styles/ModernProgressBarStyles.xaml | 17 +++++ 3 files changed, 93 insertions(+) create mode 100644 Russkyc.ModernControls.WPF/Converters/OrientationToAngleConverter.cs diff --git a/Russkyc.ModernControls.WPF/Controls/ModernProgressbar.cs b/Russkyc.ModernControls.WPF/Controls/ModernProgressbar.cs index c8be3d7..f339562 100644 --- a/Russkyc.ModernControls.WPF/Controls/ModernProgressbar.cs +++ b/Russkyc.ModernControls.WPF/Controls/ModernProgressbar.cs @@ -33,6 +33,18 @@ public partial class ModernProgressbar : Control [DependencyProperty(typeof(double))] public static readonly DependencyProperty ProgressProperty; + [DependencyProperty(typeof(bool))] + public static readonly DependencyProperty ShowProgressProperty; + + [DependencyProperty(typeof(Thickness))] + public static readonly DependencyProperty TextMarginProperty; + + [DependencyProperty(typeof(HorizontalAlignment))] + public static readonly DependencyProperty TextAlignmentProperty; + + [DependencyProperty(typeof(Orientation))] + public static readonly DependencyProperty OrientationProperty; + // Border Styling [DependencyProperty(typeof(CornerRadius))] public static readonly DependencyProperty CornerRadiusProperty; diff --git a/Russkyc.ModernControls.WPF/Converters/OrientationToAngleConverter.cs b/Russkyc.ModernControls.WPF/Converters/OrientationToAngleConverter.cs new file mode 100644 index 0000000..2b19c7c --- /dev/null +++ b/Russkyc.ModernControls.WPF/Converters/OrientationToAngleConverter.cs @@ -0,0 +1,64 @@ +// MIT License +// +// Copyright (c) 2023 Russell Camo (Russkyc) +// +// Permission is hereby granted, free of charge, to any person obtaining a copy +// of this software and associated documentation files (the "Software"), to deal +// in the Software without restriction, including without limitation the rights +// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +// copies of the Software, and to permit persons to whom the Software is +// furnished to do so, subject to the following conditions: +// +// The above copyright notice and this permission notice shall be included in all +// copies or substantial portions of the Software. +// +// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +// SOFTWARE. + +using System; +using System.Globalization; +using System.Windows.Controls; +using System.Windows.Data; + +namespace org.russkyc.moderncontrols.Converters; + +[ValueConversion(typeof(Orientation), typeof(double))] +public class OrientationToAngleConverter : IValueConverter +{ + public static OrientationToAngleConverter Instance = new(); + + public object Convert(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is not Orientation orientation) + { + return 0; + } + + if (orientation is Orientation.Horizontal) + { + return 0; + } + + return -90; + } + + public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) + { + if (value is not double orientation) + { + return Orientation.Horizontal; + } + + if (orientation is -90) + { + return Orientation.Vertical; + } + + return Orientation.Horizontal; + } +} diff --git a/Russkyc.ModernControls.WPF/Styles/ModernProgressBarStyles.xaml b/Russkyc.ModernControls.WPF/Styles/ModernProgressBarStyles.xaml index 317547d..f502340 100644 --- a/Russkyc.ModernControls.WPF/Styles/ModernProgressBarStyles.xaml +++ b/Russkyc.ModernControls.WPF/Styles/ModernProgressBarStyles.xaml @@ -5,6 +5,9 @@ xmlns:russkyc="clr-namespace:org.russkyc.moderncontrols">