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 @@ - -