From 969f58e50199e3ac3f7c15bdad2461f5ad51c011 Mon Sep 17 00:00:00 2001 From: NaBian <836904362@qq.com> Date: Tue, 30 Oct 2018 00:16:04 +0800 Subject: [PATCH] add PreviewSlider --- HandyControl/Controls/Slider/PreviewSlider.cs | 80 +++++++++++++++++- HandyControl/Controls/TabControl/TabItem.cs | 2 +- .../Themes/Styles/Base/LoadingBaseStyle.xaml | 2 +- .../Styles/Base/LoadingCircleBaseStyle.xaml | 2 +- .../Styles/Base/LoadingLineBaseStyle.xaml | 2 +- .../Styles/Base/ScrollViewerBaseStyle.xaml | 4 +- HandyControl/Themes/Styles/Loading.xaml | 16 ++-- HandyControl/Themes/Styles/ScrollViewer.xaml | 2 +- HandyControl/Themes/Styles/Slider.xaml | 72 ++++++++++++++-- HandyControl/Themes/Styles/TabControl.xaml | 8 +- HandyControlDemo/Data/MessageToken.cs | 2 + HandyControlDemo/Data/MessageToken.tt | 3 +- HandyControlDemo/HandyControlDemo.csproj | 8 ++ .../Properties/Langs/Lang.Designer.cs | 9 ++ .../Properties/Langs/Lang.en.resx | 3 + HandyControlDemo/Properties/Langs/Lang.resx | 3 + .../Img/LeftMainContent/HoverMenu_16x.png | Bin 0 -> 240 bytes .../Controls/PreviewSliderDemoCtl.xaml | 13 +++ .../Controls/PreviewSliderDemoCtl.xaml.cs | 11 +++ .../UserControl/Main/LeftMainContent.xaml | 7 +- 20 files changed, 218 insertions(+), 31 deletions(-) create mode 100644 HandyControlDemo/Resources/Img/LeftMainContent/HoverMenu_16x.png create mode 100644 HandyControlDemo/UserControl/Controls/PreviewSliderDemoCtl.xaml create mode 100644 HandyControlDemo/UserControl/Controls/PreviewSliderDemoCtl.xaml.cs diff --git a/HandyControl/Controls/Slider/PreviewSlider.cs b/HandyControl/Controls/Slider/PreviewSlider.cs index 86c97120..9d4490d5 100644 --- a/HandyControl/Controls/Slider/PreviewSlider.cs +++ b/HandyControl/Controls/Slider/PreviewSlider.cs @@ -1,10 +1,86 @@ -using System.Windows.Controls; +using System; +using System.Windows; +using System.Windows.Controls; +using System.Windows.Input; +using System.Windows.Media; +using HandyControl.Data; // ReSharper disable once CheckNamespace namespace HandyControl.Controls { + [TemplatePart(Name = PreviewContentKey, Type = typeof(ContentControl))] public class PreviewSlider : Slider { - + private const string PreviewContentKey = "PART_ContentBorder"; + + private ContentControl _previewContent; + + private TranslateTransform _transform; + + /// + /// 预览内容 + /// + public static readonly DependencyProperty PreviewContentProperty = DependencyProperty.Register( + "PreviewContent", typeof(object), typeof(PreviewSlider), new PropertyMetadata(default(object))); + + /// + /// 预览内容 + /// + public object PreviewContent + { + get => GetValue(PreviewContentProperty); + set => SetValue(PreviewContentProperty, value); + } + + public static readonly DependencyProperty PreviewPositionProperty = DependencyProperty.Register( + "PreviewPosition", typeof(double), typeof(PreviewSlider), new PropertyMetadata(default(double))); + + public double PreviewPosition + { + get => (double) GetValue(PreviewPositionProperty); + set => SetValue(PreviewPositionProperty, value); + } + + /// + /// 值改变事件 + /// + public static readonly RoutedEvent PreviewPositionChangedEvent = + EventManager.RegisterRoutedEvent("PreviewPositionChanged", RoutingStrategy.Bubble, + typeof(EventHandler>), typeof(PreviewSlider)); + + /// + /// 值改变事件 + /// + public event EventHandler> PreviewPositionChanged + { + add => AddHandler(PreviewPositionChangedEvent, value); + remove => RemoveHandler(PreviewPositionChangedEvent, value); + } + + protected override void OnMouseMove(MouseEventArgs e) + { + base.OnMouseMove(e); + + var p = e.GetPosition(this); + _transform.X = p.X - _previewContent.ActualWidth/2; + + PreviewPosition = p.X / ActualWidth * Maximum; + RaiseEvent(new FunctionEventArgs(PreviewPositionChangedEvent, this) + { + Info = PreviewPosition + }); + } + + public override void OnApplyTemplate() + { + base.OnApplyTemplate(); + _previewContent = Template.FindName(PreviewContentKey, this) as ContentControl; + + if (_previewContent != null) + { + _transform = new TranslateTransform(); + _previewContent.RenderTransform = _transform; + } + } } } \ No newline at end of file diff --git a/HandyControl/Controls/TabControl/TabItem.cs b/HandyControl/Controls/TabControl/TabItem.cs index 284a815f..f93e22b4 100644 --- a/HandyControl/Controls/TabControl/TabItem.cs +++ b/HandyControl/Controls/TabControl/TabItem.cs @@ -19,7 +19,7 @@ namespace HandyControl.Controls private Button _buttonClose; /// - /// 动画速度 + /// 动画速度 /// private const int AnimationSpeed = 150; diff --git a/HandyControl/Themes/Styles/Base/LoadingBaseStyle.xaml b/HandyControl/Themes/Styles/Base/LoadingBaseStyle.xaml index d671eaab..d59fd341 100644 --- a/HandyControl/Themes/Styles/Base/LoadingBaseStyle.xaml +++ b/HandyControl/Themes/Styles/Base/LoadingBaseStyle.xaml @@ -2,7 +2,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:controls="clr-namespace:HandyControl.Controls"> - diff --git a/HandyControl/Themes/Styles/Base/LoadingCircleBaseStyle.xaml b/HandyControl/Themes/Styles/Base/LoadingCircleBaseStyle.xaml index 4026123f..e19f3d84 100644 --- a/HandyControl/Themes/Styles/Base/LoadingCircleBaseStyle.xaml +++ b/HandyControl/Themes/Styles/Base/LoadingCircleBaseStyle.xaml @@ -6,7 +6,7 @@ - diff --git a/HandyControl/Themes/Styles/Base/ScrollViewerBaseStyle.xaml b/HandyControl/Themes/Styles/Base/ScrollViewerBaseStyle.xaml index f8d233a7..9cb9868f 100644 --- a/HandyControl/Themes/Styles/Base/ScrollViewerBaseStyle.xaml +++ b/HandyControl/Themes/Styles/Base/ScrollViewerBaseStyle.xaml @@ -158,7 +158,7 @@ - + @@ -206,7 +206,7 @@ - - - - - - diff --git a/HandyControl/Themes/Styles/ScrollViewer.xaml b/HandyControl/Themes/Styles/ScrollViewer.xaml index 1f8a4cd7..cb14a780 100644 --- a/HandyControl/Themes/Styles/ScrollViewer.xaml +++ b/HandyControl/Themes/Styles/ScrollViewer.xaml @@ -9,6 +9,6 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/HandyControl/Themes/Styles/TabControl.xaml b/HandyControl/Themes/Styles/TabControl.xaml index 2786f569..bd1ad7a7 100644 --- a/HandyControl/Themes/Styles/TabControl.xaml +++ b/HandyControl/Themes/Styles/TabControl.xaml @@ -12,7 +12,7 @@ - -