Synchronize the Net40
This commit is contained in:
1 parent
a8284c2564
commit
4d4fb36d1b
68 files changed
+1246
-272
No files matched your search
@@ -1,4 +1,8 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Data;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Tools.Converter;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
@@ -10,5 +14,37 @@ namespace HandyControl.Controls
|
||||
public static void SetCornerRadius(DependencyObject element, CornerRadius value) => element.SetValue(CornerRadiusProperty, value);
|
||||
|
||||
public static CornerRadius GetCornerRadius(DependencyObject element) => (CornerRadius)element.GetValue(CornerRadiusProperty);
|
||||
|
||||
public static readonly DependencyProperty CircularProperty = DependencyProperty.RegisterAttached(
|
||||
"Circular", typeof(bool), typeof(BorderElement), new PropertyMetadata(ValueBoxes.FalseBox, OnCircularChanged));
|
||||
|
||||
private static void OnCircularChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is Border border)
|
||||
{
|
||||
if ((bool)e.NewValue)
|
||||
{
|
||||
var binding = new MultiBinding
|
||||
{
|
||||
Converter = new BorderCircularConverter()
|
||||
};
|
||||
binding.Bindings.Add(new Binding(FrameworkElement.ActualWidthProperty.Name) { Source = border });
|
||||
binding.Bindings.Add(new Binding(FrameworkElement.ActualHeightProperty.Name) { Source = border });
|
||||
border.SetBinding(Border.CornerRadiusProperty, binding);
|
||||
}
|
||||
else
|
||||
{
|
||||
BindingOperations.ClearBinding(border, FrameworkElement.MinWidthProperty);
|
||||
BindingOperations.ClearBinding(border, FrameworkElement.MinHeightProperty);
|
||||
BindingOperations.ClearBinding(border, Border.CornerRadiusProperty);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetCircular(DependencyObject element, bool value)
|
||||
=> element.SetValue(CircularProperty, value);
|
||||
|
||||
public static bool GetCircular(DependencyObject element)
|
||||
=> (bool)element.GetValue(CircularProperty);
|
||||
}
|
||||
}
|
||||
@@ -14,7 +14,7 @@ namespace HandyControl.Controls
|
||||
{
|
||||
if (d is UIElement element)
|
||||
{
|
||||
CreateTrriger(element, (string) e.NewValue);
|
||||
CreateTrigger(element, (string)e.NewValue);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,9 +25,9 @@ namespace HandyControl.Controls
|
||||
=> element.SetValue(CommandBindingProperty, value);
|
||||
|
||||
private static CommandBinding GetCommandBinding(DependencyObject element)
|
||||
=> (CommandBinding) element.GetValue(CommandBindingProperty);
|
||||
=> (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);
|
||||
@@ -42,6 +42,6 @@ namespace HandyControl.Controls
|
||||
=> element.SetValue(LinkProperty, value);
|
||||
|
||||
public static string GetLink(DependencyObject element)
|
||||
=> (string) element.GetValue(LinkProperty);
|
||||
=> (string)element.GetValue(LinkProperty);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public interface IGravatarGenerator
|
||||
{
|
||||
object GetGravatar(string id);
|
||||
}
|
||||
}
|
||||
@@ -47,6 +47,7 @@ namespace HandyControl.Controls
|
||||
_textBox = GetTemplateChild(ElementTextBox) as WatermarkTextBox;
|
||||
if (_textBox != null)
|
||||
{
|
||||
_textBox.Text = Text;
|
||||
SetBinding(TextProperty, new Binding(TextProperty.Name)
|
||||
{
|
||||
Source = _textBox,
|
||||
|
||||
@@ -5,6 +5,8 @@ using System.Windows.Media;
|
||||
using System.Windows.Media.Animation;
|
||||
using System.Windows.Shapes;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Expression.Drawing;
|
||||
using HandyControl.Tools.Extension;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
@@ -17,6 +19,11 @@ namespace HandyControl.Controls
|
||||
/// </summary>
|
||||
private Storyboard _storyboard;
|
||||
|
||||
/// <summary>
|
||||
/// 路径长度
|
||||
/// </summary>
|
||||
private double _pathLength;
|
||||
|
||||
/// <summary>
|
||||
/// 路径
|
||||
/// </summary>
|
||||
@@ -47,8 +54,7 @@ namespace HandyControl.Controls
|
||||
/// 路径长度
|
||||
/// </summary>
|
||||
public static readonly DependencyProperty PathLengthProperty = DependencyProperty.Register(
|
||||
"PathLength", typeof(double), typeof(AnimationPath), new FrameworkPropertyMetadata(ValueBoxes.Double0Box,
|
||||
OnPropertiesChanged));
|
||||
"PathLength", typeof(double), typeof(AnimationPath), new FrameworkPropertyMetadata(ValueBoxes.Double0Box, OnPropertiesChanged));
|
||||
|
||||
/// <summary>
|
||||
/// 路径长度
|
||||
@@ -146,34 +152,47 @@ namespace HandyControl.Controls
|
||||
remove => RemoveHandler(CompletedEvent, value);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新路径
|
||||
/// </summary>
|
||||
private void UpdatePath()
|
||||
{
|
||||
if (!Duration.HasTimeSpan || !IsPlaying) return;
|
||||
StrokeDashOffset = PathLength;
|
||||
|
||||
_pathLength = PathLength > 0 ? PathLength : Data.GetTotalLength(new Size(ActualWidth, ActualHeight), StrokeThickness);
|
||||
|
||||
if (MathHelper.IsVerySmall(_pathLength)) return;
|
||||
|
||||
StrokeDashOffset = _pathLength;
|
||||
StrokeDashArray = new DoubleCollection(new List<double>
|
||||
{
|
||||
PathLength,
|
||||
PathLength
|
||||
_pathLength,
|
||||
_pathLength
|
||||
});
|
||||
|
||||
//定义动画
|
||||
if (_storyboard != null)
|
||||
{
|
||||
_storyboard.Stop();
|
||||
_storyboard.Completed -= Storyboard_Completed;
|
||||
}
|
||||
_storyboard = new Storyboard
|
||||
{
|
||||
RepeatBehavior = RepeatBehavior
|
||||
};
|
||||
_storyboard.Completed += (s, e) => RaiseEvent(new RoutedEventArgs(CompletedEvent));
|
||||
_storyboard.Completed += Storyboard_Completed;
|
||||
|
||||
var frames = new DoubleAnimationUsingKeyFrames();
|
||||
//开始位置
|
||||
var frame0 = new LinearDoubleKeyFrame
|
||||
{
|
||||
Value = PathLength,
|
||||
Value = _pathLength,
|
||||
KeyTime = KeyTime.FromTimeSpan(TimeSpan.Zero)
|
||||
};
|
||||
//结束位置
|
||||
var frame1 = new LinearDoubleKeyFrame
|
||||
{
|
||||
Value = -PathLength,
|
||||
Value = -_pathLength,
|
||||
KeyTime = KeyTime.FromTimeSpan(Duration.TimeSpan)
|
||||
};
|
||||
frames.KeyFrames.Add(frame0);
|
||||
@@ -185,5 +204,7 @@ namespace HandyControl.Controls
|
||||
|
||||
_storyboard.Begin();
|
||||
}
|
||||
|
||||
private void Storyboard_Completed(object sender, EventArgs e) => RaiseEvent(new RoutedEventArgs(CompletedEvent));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,64 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using HandyControl.Data;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// 标记
|
||||
/// </summary>
|
||||
public class Badge : ContentControl
|
||||
{
|
||||
public static readonly DependencyProperty TextProperty = DependencyProperty.Register(
|
||||
"Text", typeof(string), typeof(Badge), new PropertyMetadata(default(string)));
|
||||
|
||||
public string Text
|
||||
{
|
||||
get => (string)GetValue(TextProperty);
|
||||
set => SetValue(TextProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ValueProperty = DependencyProperty.Register(
|
||||
"Value", typeof(int), typeof(Badge), new PropertyMetadata(ValueBoxes.Int0Box, OnValueChanged));
|
||||
|
||||
private static void OnValueChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var ctl = (Badge)d;
|
||||
var v = (int)e.NewValue;
|
||||
ctl.Text = v <= ctl.Maximum ? v.ToString() : $"{ctl.Maximum}+";
|
||||
}
|
||||
|
||||
public int Value
|
||||
{
|
||||
get => (int)GetValue(ValueProperty);
|
||||
set => SetValue(ValueProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsDotProperty = DependencyProperty.Register(
|
||||
"IsDot", typeof(bool), typeof(Badge), new PropertyMetadata(ValueBoxes.FalseBox));
|
||||
|
||||
public bool IsDot
|
||||
{
|
||||
get => (bool)GetValue(IsDotProperty);
|
||||
set => SetValue(IsDotProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty MaximumProperty = DependencyProperty.Register(
|
||||
"Maximum", typeof(int), typeof(Badge), new PropertyMetadata(ValueBoxes.Int99Box, OnValueChanged));
|
||||
|
||||
public int Maximum
|
||||
{
|
||||
get => (int)GetValue(MaximumProperty);
|
||||
set => SetValue(MaximumProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty BadgeMarginProperty = DependencyProperty.Register(
|
||||
"BadgeMargin", typeof(Thickness), typeof(Badge), new PropertyMetadata(default(Thickness)));
|
||||
|
||||
public Thickness BadgeMargin
|
||||
{
|
||||
get => (Thickness)GetValue(BadgeMarginProperty);
|
||||
set => SetValue(BadgeMarginProperty, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class Dialog : ContentControl
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
using HandyControl.Tools;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class Gravatar : ContentControl
|
||||
{
|
||||
public static readonly DependencyProperty GeneratorProperty = DependencyProperty.Register(
|
||||
"Generator", typeof(IGravatarGenerator), typeof(Gravatar), new PropertyMetadata(new GithubGravatarGenerator()));
|
||||
|
||||
public IGravatarGenerator Generator
|
||||
{
|
||||
get => (IGravatarGenerator)GetValue(GeneratorProperty);
|
||||
set => SetValue(GeneratorProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IdProperty = DependencyProperty.Register(
|
||||
"Id", typeof(string), typeof(Gravatar), new PropertyMetadata(default(string), OnIdChanged));
|
||||
|
||||
private static void OnIdChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var ctl = (Gravatar)d;
|
||||
if (ctl.Source != null) return;
|
||||
ctl.Content = ctl.Generator.GetGravatar((string)e.NewValue);
|
||||
}
|
||||
|
||||
public string Id
|
||||
{
|
||||
get => (string)GetValue(IdProperty);
|
||||
set => SetValue(IdProperty, value);
|
||||
}
|
||||
|
||||
|
||||
public static readonly DependencyProperty SourceProperty = DependencyProperty.Register(
|
||||
"Source", typeof(ImageSource), typeof(Gravatar), new PropertyMetadata(default(ImageSource), OnSourceChanged));
|
||||
|
||||
private static void OnSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var ctl = (Gravatar)d;
|
||||
ctl.Background = new ImageBrush((ImageSource)e.NewValue);
|
||||
}
|
||||
|
||||
public ImageSource Source
|
||||
{
|
||||
get => (ImageSource)GetValue(SourceProperty);
|
||||
set => SetValue(SourceProperty, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// 用以代替Grid
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 当不需要Grid的行、列分隔等功能时建议用此轻量级类代替
|
||||
/// </remarks>
|
||||
public class SimplePanel : Panel
|
||||
{
|
||||
protected override Size MeasureOverride(Size availableSize)
|
||||
{
|
||||
var maxSize = new Size();
|
||||
var children = InternalChildren;
|
||||
|
||||
for (int i = 0, count = children.Count; i < count; ++i)
|
||||
{
|
||||
var child = children[i];
|
||||
if (child != null)
|
||||
{
|
||||
child.Measure(availableSize);
|
||||
maxSize.Width = Math.Max(maxSize.Width, child.DesiredSize.Width);
|
||||
maxSize.Height = Math.Max(maxSize.Height, child.DesiredSize.Height);
|
||||
}
|
||||
}
|
||||
|
||||
return maxSize;
|
||||
}
|
||||
|
||||
protected override Size ArrangeOverride(Size arrangeSize)
|
||||
{
|
||||
foreach (UIElement child in InternalChildren)
|
||||
{
|
||||
child?.Arrange(new Rect(arrangeSize));
|
||||
}
|
||||
|
||||
return arrangeSize;
|
||||
}
|
||||
}
|
||||
}
|
||||
File renamed without changes.
@@ -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
|
||||
{
|
||||
/// <summary>
|
||||
/// 波浪进度条
|
||||
/// </summary>
|
||||
[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);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user