Merge pull request #111 from HandyOrg/pr/110

Pr/110
This commit is contained in:
NaBian authored and GitHub committed 2019-06-27 23:58:23 +08:00
commit 4c608c2b84
6 files changed
+63 -22

No files matched your search

@@ -12,6 +12,15 @@ namespace HandyControl.Controls
=> element.SetValue(HighlightBrushProperty, value);
public static Brush GetHighlightBrush(DependencyObject element)
=> (Brush) element.GetValue(HighlightBrushProperty);
=> (Brush) element.GetValue(HighlightBrushProperty);
public static readonly DependencyProperty TextProperty = DependencyProperty.RegisterAttached(
"Text", typeof(string), typeof(VisualElement), new PropertyMetadata(default(string)));
public static void SetText(DependencyObject element, string value)
=> element.SetValue(TextProperty, value);
public static string GetText(DependencyObject element)
=> (string) element.GetValue(TextProperty);
}
}
@@ -25,7 +25,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Controls\Slider\RangeSlider\TwoWayRangeBase.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Interactivity\Commands\OpenLinkCommand.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\BorderCircularClipConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\NameReferenceConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Converter\Number2PercentageConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Extension\FrameworkElementExtension.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\Extension\StringExtension.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Tools\GlobalShortcut.cs" />
@@ -18,5 +18,5 @@
<converter:BorderCircularClipConverter x:Key="BorderCircularClipConverter"/>
<converter:BorderCircularConverter x:Key="BorderCircularConverter"/>
<converter:Object2VisibilityConverter x:Key="Object2VisibilityConverter"/>
<converter:Number2PercentageConverter x:Key="Number2PercentageConverter"/>
</ResourceDictionary>
@@ -16,6 +16,14 @@
</LinearGradientBrush>
<Style x:Key="ProgressBarBaseStyle" TargetType="ProgressBar">
<Setter Property="controls:VisualElement.Text">
<Setter.Value>
<MultiBinding Converter="{StaticResource Number2PercentageConverter}" StringFormat="{}{0} %">
<Binding Path="Value" RelativeSource="{RelativeSource Self}"/>
<Binding Path="Maximum" RelativeSource="{RelativeSource Self}"/>
</MultiBinding>
</Setter.Value>
</Setter>
<Setter Property="Height" Value="20"/>
<Setter Property="controls:BorderElement.CornerRadius" Value="4"/>
<Setter Property="Background" Value="{DynamicResource SecondaryRegionBrush}"/>
@@ -33,7 +41,7 @@
<Rectangle x:Name="PART_GlowRect" Fill="{StaticResource ProgressBarIndicatorAnimatedFill}" HorizontalAlignment="Left" Margin="-100,0,0,0" Width="100"/>
</Border>
</Decorator>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="{DynamicResource TextIconBrush}" Text="{Binding Value,RelativeSource={RelativeSource TemplatedParent},StringFormat={}{0} %}"/>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="{DynamicResource TextIconBrush}" Text="{Binding Path=(controls:VisualElement.Text),RelativeSource={RelativeSource TemplatedParent}}"/>
</controls:SimplePanel>
</controls:SimplePanel>
</ControlTemplate>
@@ -41,7 +49,12 @@
</Setter>
</Style>
<Style x:Key="ProgressBarStripeBaseStyle" BasedOn="{StaticResource ProgressBarBaseStyle}" TargetType="ProgressBar">
<Style x:Key="ProgressBarStripeBaseStyle" TargetType="ProgressBar">
<Setter Property="Height" Value="20"/>
<Setter Property="controls:BorderElement.CornerRadius" Value="4"/>
<Setter Property="Background" Value="{DynamicResource SecondaryRegionBrush}"/>
<Setter Property="BorderBrush" Value="{DynamicResource BorderBrush}"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="ProgressBar">
@@ -1,17 +0,0 @@
using System;
using System.ComponentModel;
using System.Globalization;
// ReSharper disable ConditionIsAlwaysTrueOrFalse
// ReSharper disable HeuristicUnreachableCode
namespace HandyControl.Tools.Converter
{
public class NameReferenceConverter : System.Windows.Markup.NameReferenceConverter
{
public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
=> context == null ? null : base.ConvertFrom(context, culture, value);
public override object ConvertTo(ITypeDescriptorContext context, CultureInfo culture, object value, Type destinationType)
=> context == null ? null : base.ConvertTo(context, culture, value, destinationType);
}
}
@@ -0,0 +1,36 @@
using System;
using System.Globalization;
using System.Windows.Data;
using HandyControl.Expression.Drawing;
using HandyControl.Tools.Extension;
namespace HandyControl.Tools.Converter
{
public class Number2PercentageConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
{
if (values == null || values.Length != 2) return .0;
var obj1 = values[0];
var obj2 = values[1];
if (obj1 == null || obj2 == null) return .0;
var str1 = values[0].ToString();
var str2 = values[1].ToString();
var v1 = str1.Value<double>();
var v2 = str2.Value<double>();
if (MathHelper.IsVerySmall(v2)) return 100.0;
return v1 / v2 * 100;
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
{
throw new NotImplementedException();
}
}
}