Adjust project structure

This commit is contained in:
NaBian committed 2019-04-05 22:23:19 +08:00
1 parent d38912f5da
commit e3c436f939
2111 files changed
+14028 -47199

No files matched your search

@@ -0,0 +1,27 @@
using System.Windows;
using System.Windows.Controls;
namespace HandyControl.Controls
{
public class CompareSlider : Slider
{
public static readonly DependencyProperty TargetContentProperty = DependencyProperty.Register(
"TargetContent", typeof(object), typeof(CompareSlider), new PropertyMetadata(default(object)));
public static readonly DependencyProperty SourceContentProperty = DependencyProperty.Register(
"SourceContent", typeof(object), typeof(CompareSlider), new PropertyMetadata(default(object)));
public object TargetContent
{
get => GetValue(TargetContentProperty);
set => SetValue(TargetContentProperty, value);
}
public object SourceContent
{
get => GetValue(SourceContentProperty);
set => SetValue(SourceContentProperty, value);
}
}
}
@@ -0,0 +1,117 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
namespace HandyControl.Controls
{
public class CompareTrack : Track
{
protected override Size ArrangeOverride(Size arrangeSize)
{
base.ArrangeOverride(arrangeSize);
var isVertical = Orientation == Orientation.Vertical;
ComputeSliderLengths(arrangeSize, isVertical, out var decreaseButtonLength, out var thumbLength,
out var increaseButtonLength);
var offset = new Point();
var pieceSize = arrangeSize;
var isDirectionReversed = IsDirectionReversed;
if (isVertical)
{
CoerceLength(ref decreaseButtonLength, arrangeSize.Height);
CoerceLength(ref increaseButtonLength, arrangeSize.Height);
CoerceLength(ref thumbLength, arrangeSize.Height);
offset.Y = isDirectionReversed ? decreaseButtonLength + thumbLength : 0.0;
pieceSize.Height = increaseButtonLength;
IncreaseRepeatButton?.Arrange(new Rect(offset, pieceSize));
offset.Y = isDirectionReversed ? 0.0 : increaseButtonLength + thumbLength;
pieceSize.Height = decreaseButtonLength;
if (DecreaseRepeatButton != null)
{
DecreaseRepeatButton.Arrange(new Rect(offset, pieceSize));
DecreaseRepeatButton.Height = pieceSize.Height;
}
offset.Y = isDirectionReversed ? decreaseButtonLength : increaseButtonLength;
pieceSize.Height = thumbLength;
Thumb?.Arrange(new Rect(offset, pieceSize));
}
else
{
CoerceLength(ref decreaseButtonLength, arrangeSize.Width);
CoerceLength(ref increaseButtonLength, arrangeSize.Width);
CoerceLength(ref thumbLength, arrangeSize.Width);
offset.X = isDirectionReversed ? increaseButtonLength + thumbLength : 0.0;
pieceSize.Width = decreaseButtonLength;
DecreaseRepeatButton?.Arrange(new Rect(offset, pieceSize));
offset.X = isDirectionReversed ? 0.0 : decreaseButtonLength + thumbLength;
pieceSize.Width = increaseButtonLength;
if (IncreaseRepeatButton != null)
{
IncreaseRepeatButton.Arrange(new Rect(offset, pieceSize));
IncreaseRepeatButton.Width = pieceSize.Width;
}
offset.X = isDirectionReversed ? increaseButtonLength : decreaseButtonLength;
pieceSize.Width = thumbLength;
Thumb?.Arrange(new Rect(offset, pieceSize));
}
return arrangeSize;
}
private void ComputeSliderLengths(Size arrangeSize, bool isVertical, out double decreaseButtonLength,
out double thumbLength, out double increaseButtonLength)
{
var min = Minimum;
var range = Math.Max(0.0, Maximum - min);
var offset = Math.Min(range, Value - min);
double trackLength;
// Compute thumb size
if (isVertical)
{
trackLength = arrangeSize.Height;
thumbLength = Thumb?.DesiredSize.Height ?? 0;
}
else
{
trackLength = arrangeSize.Width;
thumbLength = Thumb?.DesiredSize.Width ?? 0;
}
CoerceLength(ref thumbLength, trackLength);
var remainingTrackLength = trackLength - thumbLength;
decreaseButtonLength = remainingTrackLength * offset / range;
CoerceLength(ref decreaseButtonLength, remainingTrackLength);
increaseButtonLength = remainingTrackLength - decreaseButtonLength;
CoerceLength(ref increaseButtonLength, remainingTrackLength);
}
private static void CoerceLength(ref double componentLength, double trackLength)
{
if (componentLength < 0)
componentLength = 0.0;
else if (componentLength > trackLength || double.IsNaN(componentLength))
componentLength = trackLength;
}
}
}
@@ -0,0 +1,93 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
using HandyControl.Data;
namespace HandyControl.Controls
{
[TemplatePart(Name = PreviewContentKey, Type = typeof(ContentControl))]
[TemplatePart(Name = TracKKey, Type = typeof(Track))]
public class PreviewSlider : Slider
{
private const string PreviewContentKey = "PART_ContentBorder";
private const string TracKKey = "PART_Track";
private ContentControl _previewContent;
private TranslateTransform _transform;
private Track _track;
/// <summary>
/// 预览内容
/// </summary>
public static readonly DependencyProperty PreviewContentProperty = DependencyProperty.Register(
"PreviewContent", typeof(object), typeof(PreviewSlider), new PropertyMetadata(default(object)));
/// <summary>
/// 预览内容
/// </summary>
public object PreviewContent
{
get => GetValue(PreviewContentProperty);
set => SetValue(PreviewContentProperty, value);
}
public static readonly DependencyProperty PreviewPositionProperty = DependencyProperty.Register(
"PreviewPosition", typeof(double), typeof(PreviewSlider), new PropertyMetadata(ValueBoxes.Double0Box));
public double PreviewPosition
{
get => (double) GetValue(PreviewPositionProperty);
set => SetValue(PreviewPositionProperty, value);
}
/// <summary>
/// 值改变事件
/// </summary>
public static readonly RoutedEvent PreviewPositionChangedEvent =
EventManager.RegisterRoutedEvent("PreviewPositionChanged", RoutingStrategy.Bubble,
typeof(EventHandler<FunctionEventArgs<double>>), typeof(PreviewSlider));
/// <summary>
/// 值改变事件
/// </summary>
public event EventHandler<FunctionEventArgs<double>> PreviewPositionChanged
{
add => AddHandler(PreviewPositionChangedEvent, value);
remove => RemoveHandler(PreviewPositionChangedEvent, value);
}
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
var p = e.GetPosition(_track);
_transform.X = p.X - _previewContent.ActualWidth/2;
PreviewPosition = p.X / _track.ActualWidth * Maximum;
RaiseEvent(new FunctionEventArgs<double>(PreviewPositionChangedEvent, this)
{
Info = PreviewPosition
});
}
public override void OnApplyTemplate()
{
base.OnApplyTemplate();
_previewContent = Template.FindName(PreviewContentKey, this) as ContentControl;
_track = Template.FindName(TracKKey, this) as Track;
if (_previewContent != null)
{
_transform = new TranslateTransform();
_previewContent.RenderTransform = _transform;
}
}
}
}