add CoverFlow

This commit is contained in:
NaBian committed 2019-01-06 16:55:04 +08:00
1 parent ad6083fe78
commit 05fa5719a3
32 files changed
+846 -125

No files matched your search

@@ -0,0 +1,16 @@
using System.Windows;
namespace HandyControl.Controls
{
public class HeaderedSelectableItem : SelectableItem
{
public static readonly DependencyProperty HeaderProperty = DependencyProperty.Register(
"Header", typeof(object), typeof(HeaderedSelectableItem), new PropertyMetadata(default(object)));
public object Header
{
get => GetValue(HeaderProperty);
set => SetValue(HeaderProperty, value);
}
}
}
+11
View File
@@ -0,0 +1,11 @@
using System.Windows;
namespace HandyControl.Controls
{
public interface ISelectable
{
event RoutedEventHandler Selected;
bool IsSelected { get; set; }
}
}
@@ -0,0 +1,41 @@
using System.Windows;
using HandyControl.Data;
namespace HandyControl.Controls
{
/// <summary>
/// 规则ItemsControl
/// </summary>
/// <remarks>
/// 该类的每一项都具有相同的大小和外边距
/// </remarks>
public class RegularItemsControl : SimpleItemsControl
{
public static readonly DependencyProperty ItemWidthProperty = DependencyProperty.Register(
"ItemWidth", typeof(double), typeof(RegularItemsControl), new PropertyMetadata(ValueBoxes.Double200Box));
public double ItemWidth
{
get => (double) GetValue(ItemWidthProperty);
set => SetValue(ItemWidthProperty, value);
}
public static readonly DependencyProperty ItemHeightProperty = DependencyProperty.Register(
"ItemHeight", typeof(double), typeof(RegularItemsControl), new PropertyMetadata(ValueBoxes.Double200Box));
public double ItemHeight
{
get => (double) GetValue(ItemHeightProperty);
set => SetValue(ItemHeightProperty, value);
}
public static readonly DependencyProperty ItemMarginProperty = DependencyProperty.Register(
"ItemMargin", typeof(Thickness), typeof(RegularItemsControl), new PropertyMetadata(default(Thickness)));
public Thickness ItemMargin
{
get => (Thickness) GetValue(ItemMarginProperty);
set => SetValue(ItemMarginProperty, value);
}
}
}
@@ -0,0 +1,56 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using HandyControl.Data;
namespace HandyControl.Controls
{
public class SelectableItem : ContentControl, ISelectable
{
private bool _isMouseLeftButtonDown;
protected override void OnMouseLeave(MouseEventArgs e)
{
base.OnMouseLeave(e);
_isMouseLeftButtonDown = false;
}
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
_isMouseLeftButtonDown = true;
}
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonUp(e);
if (_isMouseLeftButtonDown)
{
RaiseEvent(new RoutedEventArgs(SelectedEvent, this));
_isMouseLeftButtonDown = false;
}
}
public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register(
"IsSelected", typeof(bool), typeof(SelectableItem), new PropertyMetadata(ValueBoxes.FalseBox));
public bool IsSelected
{
get => (bool)GetValue(IsSelectedProperty);
set => SetValue(IsSelectedProperty, value);
}
public static readonly RoutedEvent SelectedEvent =
EventManager.RegisterRoutedEvent("Selected", RoutingStrategy.Bubble,
typeof(RoutedEventHandler), typeof(SelectableItem));
public event RoutedEventHandler Selected
{
add => AddHandler(SelectedEvent, value);
remove => RemoveHandler(SelectedEvent, value);
}
}
}
@@ -7,7 +7,9 @@ using System.Windows.Markup;
namespace HandyControl.Controls
{
[DefaultEvent("OnItemsChanged")]
/// <summary>
/// ItemsControl的轻量级版本
/// </summary>
[DefaultProperty("Items")]
[ContentProperty("Items")]
[TemplatePart(Name = ElementPanel, Type = typeof(Panel))]
@@ -0,0 +1,338 @@
using System;
using System.Collections.Generic;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Media.Media3D;
using HandyControl.Data;
namespace HandyControl.Controls
{
/// <summary>
/// 封面流
/// </summary>
[TemplatePart(Name = ElementViewport3D, Type = typeof(Viewport3D))]
[TemplatePart(Name = ElementCamera, Type = typeof(ProjectionCamera))]
[TemplatePart(Name = ElementVisualParent, Type = typeof(ModelVisual3D))]
public class CoverFlow : Control
{
private const string ElementViewport3D = "PART_Viewport3D";
private const string ElementCamera = "PART_Camera";
private const string ElementVisualParent = "PART_VisualParent";
/// <summary>
/// 最大显示数量的一半
/// </summary>
private const int MaxShowCountHalf = 7;
/// <summary>
/// 页码
/// </summary>
public static readonly DependencyProperty PageIndexProperty = DependencyProperty.Register(
"PageIndex", typeof(int), typeof(CoverFlow),
new PropertyMetadata(ValueBoxes.Int0Box, OnPageIndexChanged, CoercePageIndex));
private static object CoercePageIndex(DependencyObject d, object baseValue)
{
var ctl = (CoverFlow) d;
var v = (int) baseValue;
if (v < 0)
{
return 0;
}
if (v >= ctl._uriList.Count)
{
return ctl._uriList.Count - 1;
}
return v;
}
private static void OnPageIndexChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
{
var ctl = (CoverFlow) d;
ctl.UpdateIndex((int)e.NewValue, (int)e.OldValue);
}
/// <summary>
/// 是否循环
/// </summary>
public static readonly DependencyProperty LoopProperty = DependencyProperty.Register(
"Loop", typeof(bool), typeof(CoverFlow), new PropertyMetadata(ValueBoxes.FalseBox));
/// <summary>
/// 存储所有的资源标识符
/// </summary>
private readonly Dictionary<int, Uri> _uriList = new Dictionary<int, Uri>();
/// <summary>
/// 当前在显示范围内的项
/// </summary>
private readonly Dictionary<int, CoverFlowItem> _itemShowList = new Dictionary<int, CoverFlowItem>();
/// <summary>
/// 相机
/// </summary>
private ProjectionCamera _camera;
/// <summary>
/// 3d画布
/// </summary>
private Viewport3D _viewport3D;
/// <summary>
/// 项容器
/// </summary>
private ModelVisual3D _visualParent;
/// <summary>
/// 显示范围内第一个项的编号
/// </summary>
private int _firstShowIndex;
/// <summary>
/// 显示范围内最后一个项的编号
/// </summary>
private int _lastShowIndex;
/// <summary>
/// 在获取新的模板后是否需要更新项
/// </summary>
private bool _updateItems;
private bool _isLoaded;
/// <summary>
/// 跳转编号
/// </summary>
private int _jumpToIndex = -1;
public CoverFlow()
{
Loaded += (s, e) =>
{
if (_isLoaded) return;
_isLoaded = true;
if (_updateItems)
{
UpdateShowRange();
_updateItems = false;
}
if (_jumpToIndex > 0)
{
PageIndex = _jumpToIndex;
}
};
}
/// <summary>
/// 页码
/// </summary>
public int PageIndex
{
get => (int) GetValue(PageIndexProperty);
internal set => SetValue(PageIndexProperty, value);
}
/// <summary>
/// 是否循环
/// </summary>
public bool Loop
{
get => (bool)GetValue(LoopProperty);
set => SetValue(LoopProperty, value);
}
public override void OnApplyTemplate()
{
if (_viewport3D != null)
{
_viewport3D.Children.Clear();
_itemShowList.Clear();
_viewport3D.MouseLeftButtonDown -= Viewport3D_MouseLeftButtonDown;
}
base.OnApplyTemplate();
_viewport3D = GetTemplateChild(ElementViewport3D) as Viewport3D;
if (_viewport3D != null)
{
_viewport3D.MouseLeftButtonDown += Viewport3D_MouseLeftButtonDown;
}
_camera = GetTemplateChild(ElementCamera) as ProjectionCamera;
_visualParent = GetTemplateChild(ElementVisualParent) as ModelVisual3D;
if (_isLoaded)
{
UpdateShowRange();
_camera.Position = new Point3D(CoverFlowItem.Interval * PageIndex, _camera.Position.Y,
_camera.Position.Z);
}
}
/// <summary>
/// 批量添加资源
/// </summary>
/// <param name="uriList"></param>
public void AddRange(List<Uri> uriList)
{
foreach (var uri in uriList)
{
_uriList.Add(_uriList.Count, uri);
}
_updateItems = true;
}
/// <summary>
/// 添加一项资源
/// </summary>
/// <param name="uriString"></param>
public void Add(string uriString)
{
_uriList.Add(_uriList.Count, new Uri(uriString));
_updateItems = true;
}
/// <summary>
/// 添加一项资源
/// </summary>
/// <param name="uri"></param>
public void Add(Uri uri)
{
_uriList.Add(_uriList.Count, uri);
_updateItems = true;
}
/// <summary>
/// 跳转
/// </summary>
public void JumpTo(int index) => _jumpToIndex = index;
protected override void OnMouseWheel(MouseWheelEventArgs e)
{
base.OnMouseWheel(e);
if (e.Delta < 0)
{
var index = PageIndex + 1;
PageIndex = index >= _uriList.Count ? (Loop ? 0 : _uriList.Count - 1) : index;
}
else
{
var index = PageIndex - 1;
PageIndex = index < 0 ? (Loop ? _uriList.Count - 1 : 0) : index;
}
}
/// <summary>
/// 删除指定位置的项
/// </summary>
/// <param name="pos"></param>
private void Remove(int pos)
{
var item = _itemShowList[pos];
_visualParent.Children.Remove(item);
_itemShowList.Remove(pos);
}
/// <summary>
/// 移动项到指定的位置
/// </summary>
/// <param name="index"></param>
/// <param name="animated"></param>
private void Move(int index, bool animated) => _itemShowList[index].Move(PageIndex, animated);
private void Viewport3D_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
var result = (RayMeshGeometry3DHitTestResult) VisualTreeHelper.HitTest(_viewport3D, e.GetPosition(_viewport3D));
if (result != null)
{
foreach (var item in _itemShowList.Values)
{
if (item.HitTest(result.MeshHit))
{
PageIndex = item.Index;
break;
}
}
}
}
/// <summary>
/// 更新项的位置
/// </summary>
/// <param name="newIndex"></param>
/// <param name="oldIndex"></param>
private void UpdateIndex(int newIndex, int oldIndex)
{
var animate = Math.Abs(newIndex - oldIndex) < MaxShowCountHalf;
UpdateShowRange();
if (newIndex > oldIndex)
{
if (oldIndex < _firstShowIndex)
{
oldIndex = _firstShowIndex;
}
for (var i = oldIndex; i <= newIndex; i++)
{
Move(i, animate);
}
}
else
{
if (oldIndex > _lastShowIndex)
{
oldIndex = _lastShowIndex;
}
for (var i = oldIndex; i >= newIndex; i--)
{
Move(i, animate);
}
}
_camera.Position = new Point3D(CoverFlowItem.Interval * newIndex, _camera.Position.Y,
_camera.Position.Z);
}
/// <summary>
/// 更新显示范围
/// </summary>
private void UpdateShowRange()
{
var newFirstShowIndex = Math.Max(PageIndex - MaxShowCountHalf, 0);
var newLastShowIndex = Math.Min(PageIndex + MaxShowCountHalf, _uriList.Count - 1);
if (_firstShowIndex < newFirstShowIndex)
{
for (var i = _firstShowIndex; i < newFirstShowIndex; i++)
{
Remove(i);
}
}
else if (newLastShowIndex < _lastShowIndex)
{
for (var i = newLastShowIndex; i < _lastShowIndex; i++)
{
Remove(i);
}
}
for (var i = newFirstShowIndex; i <= newLastShowIndex; i++)
{
if (!_itemShowList.ContainsKey(i))
{
var cover = new CoverFlowItem(i, PageIndex, BitmapFrame.Create(_uriList[i]));
_itemShowList[i] = cover;
_visualParent.Children.Add(cover);
}
}
_firstShowIndex = newFirstShowIndex;
_lastShowIndex = newLastShowIndex;
}
}
}
@@ -0,0 +1,169 @@
using System;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Media3D;
using HandyControl.Tools;
namespace HandyControl.Controls
{
public class CoverFlowItem : ModelVisual3D
{
internal static readonly double Interval = .2;
internal static readonly double AnimationSpeed = 400;
private readonly AxisAngleRotation3D _rotation3D;
private readonly TranslateTransform3D _transform3D;
private readonly Model3DGroup _model3DGroup;
private readonly ImageSource _source;
internal int Index { get; set; }
public CoverFlowItem(int itemIndex, int currentIndex, ImageSource source)
{
Index = itemIndex;
_source = source;
_rotation3D = new AxisAngleRotation3D(new Vector3D(0, 1, 0), GetAngleByPos(currentIndex));
_transform3D = new TranslateTransform3D(GetXByPos(currentIndex), 0, GetZByPos(currentIndex));
var transformGroup = new Transform3DGroup();
transformGroup.Children.Add(new RotateTransform3D(_rotation3D));
transformGroup.Children.Add(_transform3D);
_model3DGroup = new Model3DGroup();
_model3DGroup.Children.Add(new GeometryModel3D(CreateItemGeometry(), new DiffuseMaterial(new ImageBrush(_source))));
_model3DGroup.Transform = transformGroup;
Content = _model3DGroup;
}
/// <summary>
/// 创建网格形状
/// </summary>
/// <param name="p0"></param>
/// <param name="p1"></param>
/// <param name="p2"></param>
/// <param name="p3"></param>
/// <returns></returns>
private static MeshGeometry3D CreateMeshGeometry(Point3D p0, Point3D p1, Point3D p2, Point3D p3)
{
var positions = new Point3DCollection
{
p0,
p1,
p2,
p3
};
var triangleIndices = new Int32Collection
{
0,
1,
2,
2,
3,
0
};
var textureCoordinates = new PointCollection
{
new Point(0, 1),
new Point(1, 1),
new Point(1, 0),
new Point(0, 0),
new Point(1, 0),
new Point(1, 1)
};
var normals = new Vector3DCollection
{
ArithmeticHelper.CalNormal(p0, p1, p2),
ArithmeticHelper.CalNormal(p2, p3, p0)
};
var geometry3D = new MeshGeometry3D
{
Positions = positions,
TriangleIndices = triangleIndices,
TextureCoordinates = textureCoordinates,
Normals = normals
};
geometry3D.Freeze();
return geometry3D;
}
/// <summary>
/// 创建内容形状
/// </summary>
/// <returns></returns>
private Geometry3D CreateItemGeometry()
{
var sx = _source.Width > _source.Height ? 0 : 1 - _source.Width / _source.Height;
var sy = _source.Width < _source.Height ? 0 : 1 - _source.Height / _source.Width;
var p0 = new Point3D(-1 + sx, -1 + sy, 0);
var p1 = new Point3D(1 - sx, -1 + sy, 0);
var p2 = new Point3D(1 - sx, 1 - sy, 0);
var p3 = new Point3D(-1 + sx, 1 - sy, 0);
return CreateMeshGeometry(p0, p1, p2, p3);
}
private double GetAngleByPos(int index) => Math.Sign(Index - index) * -90;
private double GetXByPos(int index)
{
Console.WriteLine(Index * Interval + Math.Sign(Index - index) * 1.5);
return Index * Interval + Math.Sign(Index - index) * 1.5;
}
private double GetZByPos(int index) => Index == index ? 1 : 0;
/// <summary>
/// 移动
/// </summary>
internal void Move(int currentIndex, bool animated)
{
if (animated || _rotation3D.HasAnimatedProperties)
{
_rotation3D.BeginAnimation(AxisAngleRotation3D.AngleProperty,
AnimationHelper.CreateAnimation(GetAngleByPos(currentIndex), AnimationSpeed));
_transform3D.BeginAnimation(TranslateTransform3D.OffsetXProperty,
AnimationHelper.CreateAnimation(GetXByPos(currentIndex), AnimationSpeed));
_transform3D.BeginAnimation(TranslateTransform3D.OffsetZProperty,
AnimationHelper.CreateAnimation(GetZByPos(currentIndex), AnimationSpeed));
}
else
{
_rotation3D.Angle = GetAngleByPos(currentIndex);
_transform3D.OffsetX = GetXByPos(currentIndex);
_transform3D.OffsetZ = GetZByPos(currentIndex);
}
}
/// <summary>
/// 命中测试
/// </summary>
/// <param name="mesh"></param>
/// <returns></returns>
internal bool HitTest(MeshGeometry3D mesh)
{
foreach (var item in _model3DGroup.Children)
{
if (item is GeometryModel3D geometryModel3D)
{
if (Equals(geometryModel3D.Geometry, mesh))
{
return true;
}
}
}
return false;
}
}
}
+2 -29
View File
@@ -4,7 +4,7 @@ using HandyControl.Data;
namespace HandyControl.Controls
{
public class CoverView : SimpleItemsControl
public class CoverView : RegularItemsControl
{
private readonly CoverViewContent _viewContent;
@@ -14,7 +14,7 @@ namespace HandyControl.Controls
{
_viewContent = new CoverViewContent {ContentHeight = ItemContentHeight};
AddHandler(CoverViewItem.SelectedEvent, new RoutedEventHandler(CoverViewItem_OnSelected));
AddHandler(SelectableItem.SelectedEvent, new RoutedEventHandler(CoverViewItem_OnSelected));
_viewContent.SetBinding(WidthProperty, new Binding(ActualWidthProperty.Name) { Source = this });
}
@@ -87,33 +87,6 @@ namespace HandyControl.Controls
set => SetValue(CoverViewContentStyleProperty, value);
}
public static readonly DependencyProperty ItemWidthProperty = DependencyProperty.Register(
"ItemWidth", typeof(double), typeof(CoverView), new PropertyMetadata(ValueBoxes.Double200Box));
public double ItemWidth
{
get => (double) GetValue(ItemWidthProperty);
set => SetValue(ItemWidthProperty, value);
}
public static readonly DependencyProperty ItemHeightProperty = DependencyProperty.Register(
"ItemHeight", typeof(double), typeof(CoverView), new PropertyMetadata(ValueBoxes.Double200Box));
public double ItemHeight
{
get => (double) GetValue(ItemHeightProperty);
set => SetValue(ItemHeightProperty, value);
}
public static readonly DependencyProperty ItemMarginProperty = DependencyProperty.Register(
"ItemMargin", typeof(Thickness), typeof(CoverView), new PropertyMetadata(default(Thickness)));
public Thickness ItemMargin
{
get => (Thickness) GetValue(ItemMarginProperty);
set => SetValue(ItemMarginProperty, value);
}
internal static readonly DependencyProperty GroupsProperty = DependencyProperty.Register(
"Groups", typeof(int), typeof(CoverView), new FrameworkPropertyMetadata(ValueBoxes.Int5Box, FrameworkPropertyMetadataOptions.AffectsMeasure, OnGroupsChanged), IsGroupsValid);
@@ -1,58 +1,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using HandyControl.Data;
namespace HandyControl.Controls
namespace HandyControl.Controls
{
public class CoverViewItem : HeaderedContentControl
{
private bool _isMouseLeftButtonDown;
protected override void OnMouseLeave(MouseEventArgs e)
{
base.OnMouseLeave(e);
_isMouseLeftButtonDown = false;
}
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
_isMouseLeftButtonDown = true;
}
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonUp(e);
if (_isMouseLeftButtonDown)
{
RaiseEvent(new RoutedEventArgs(SelectedEvent, this));
_isMouseLeftButtonDown = false;
}
}
public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register(
"IsSelected", typeof(bool), typeof(CoverViewItem), new PropertyMetadata(ValueBoxes.FalseBox));
public bool IsSelected
{
internal get => (bool) GetValue(IsSelectedProperty);
set => SetValue(IsSelectedProperty, value);
}
public static readonly RoutedEvent SelectedEvent =
EventManager.RegisterRoutedEvent("Selected", RoutingStrategy.Bubble,
typeof(RoutedEventHandler), typeof(CoverViewItem));
public event RoutedEventHandler Selected
{
add => AddHandler(SelectedEvent, value);
remove => RemoveHandler(SelectedEvent, value);
}
public class CoverViewItem : HeaderedSelectableItem
{
internal int Index { get; set; }
}
}
+18 -28
View File
@@ -7,16 +7,13 @@ using HandyControl.Tools;
namespace HandyControl.Controls
{
public class Rate : SimpleItemsControl
public class Rate : RegularItemsControl
{
public static readonly DependencyProperty ItemMarginProperty = DependencyProperty.Register(
"ItemMargin", typeof(Thickness), typeof(Rate), new PropertyMetadata(default(Thickness)));
public static readonly DependencyProperty ItemWidthProperty = DependencyProperty.Register(
"ItemWidth", typeof(double), typeof(Rate), new PropertyMetadata(ValueBoxes.Double20Box));
public static readonly DependencyProperty ItemHeightProperty = DependencyProperty.Register(
"ItemHeight", typeof(double), typeof(Rate), new PropertyMetadata(ValueBoxes.Double20Box));
static Rate()
{
ItemWidthProperty.OverrideMetadata(typeof(Rate), new PropertyMetadata(ValueBoxes.Double20Box));
ItemHeightProperty.OverrideMetadata(typeof(Rate), new PropertyMetadata(ValueBoxes.Double20Box));
}
public static readonly DependencyProperty AllowHalfProperty = DependencyProperty.Register(
"AllowHalf", typeof(bool), typeof(Rate), new FrameworkPropertyMetadata(ValueBoxes.FalseBox, FrameworkPropertyMetadataOptions.Inherits));
@@ -42,6 +39,9 @@ namespace HandyControl.Controls
public static readonly DependencyProperty ShowTextProperty = DependencyProperty.Register(
"ShowText", typeof(bool), typeof(Rate), new PropertyMetadata(ValueBoxes.FalseBox));
public static readonly DependencyProperty IsReadOnlyProperty = DependencyProperty.Register(
"IsReadOnly", typeof(bool), typeof(Rate), new PropertyMetadata(ValueBoxes.FalseBox));
private bool _isLoaded;
public Rate()
@@ -69,24 +69,6 @@ namespace HandyControl.Controls
};
}
public Thickness ItemMargin
{
get => (Thickness) GetValue(ItemMarginProperty);
set => SetValue(ItemMarginProperty, value);
}
public double ItemWidth
{
get => (double) GetValue(ItemWidthProperty);
set => SetValue(ItemWidthProperty, value);
}
public double ItemHeight
{
get => (double) GetValue(ItemHeightProperty);
set => SetValue(ItemHeightProperty, value);
}
public bool AllowHalf
{
get => (bool) GetValue(AllowHalfProperty);
@@ -135,6 +117,12 @@ namespace HandyControl.Controls
set => SetValue(ShowTextProperty, value);
}
public bool IsReadOnly
{
get => (bool)GetValue(IsReadOnlyProperty);
set => SetValue(IsReadOnlyProperty, value);
}
private void RateItemValueChanged(object sender, RoutedEventArgs e)
{
Value =
@@ -201,9 +189,11 @@ namespace HandyControl.Controls
UpdateItems();
}
private void UpdateItems()
protected override void UpdateItems()
{
if (!_isLoaded) return;
var count = (int) Value;
for (var i = 0; i < count; i++)
{
if (Items[i] is RateItem rateItem)
+13 -4
View File
@@ -20,6 +20,8 @@ namespace HandyControl.Controls
public static readonly DependencyProperty IconProperty = Rate.IconProperty.AddOwner(typeof(RateItem));
public static readonly DependencyProperty IsReadOnlyProperty = Rate.IsReadOnlyProperty.AddOwner(typeof(RateItem));
internal static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register(
"IsSelected", typeof(bool), typeof(RateItem),
new PropertyMetadata(ValueBoxes.FalseBox, OnIsSelectedChanged));
@@ -71,6 +73,12 @@ namespace HandyControl.Controls
set => SetValue(IsSelectedProperty, value);
}
public bool IsReadOnly
{
get => (bool)GetValue(IsReadOnlyProperty);
set => SetValue(IsReadOnlyProperty, value);
}
internal bool IsHalf
{
get => _isHalf;
@@ -123,6 +131,7 @@ namespace HandyControl.Controls
private void RateItem_MouseMove(object sender, MouseEventArgs e)
{
if (IsReadOnly) return;
if (!AllowHalf) return;
var p = e.GetPosition(this);
IsHalf = p.X < ActualWidth / 2;
@@ -145,7 +154,7 @@ namespace HandyControl.Controls
protected override void OnMouseEnter(MouseEventArgs e)
{
base.OnMouseEnter(e);
if (IsReadOnly) return;
_isSentValue = false;
IsSelected = true;
RaiseEvent(new RoutedEventArgs(SelectedChangedEvent) {Source = this});
@@ -154,21 +163,21 @@ namespace HandyControl.Controls
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
if (IsReadOnly) return;
_isMouseLeftButtonDown = true;
}
protected override void OnMouseLeave(MouseEventArgs e)
{
base.OnMouseLeave(e);
if (IsReadOnly) return;
_isMouseLeftButtonDown = false;
}
protected override void OnMouseLeftButtonUp(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonUp(e);
if (IsReadOnly) return;
if (_isMouseLeftButtonDown)
{
if (Index == 1 && AllowClear)
+1 -1
View File
@@ -30,7 +30,7 @@ namespace HandyControl.Controls
}
else
{
accentPolicy.AccentState = ExternDllHelper.ACCENTSTATE.ACCENT_ENABLE_TRANSPARENTGRADIENT;
return;
}
accentPolicy.AccentFlags = 2;
+14
View File
@@ -117,7 +117,13 @@
<Compile Include="Controls\Attach\LinkElement.cs" />
<Compile Include="Controls\Attach\PanelElement.cs" />
<Compile Include="Controls\Attach\VisualElement.cs" />
<Compile Include="Controls\Base\HeaderedSelectableItem.cs" />
<Compile Include="Controls\Base\ISelectable.cs" />
<Compile Include="Controls\Base\RegularItemsControl.cs" />
<Compile Include="Controls\Base\SelectableItem.cs" />
<Compile Include="Controls\Base\SimpleItemsControl.cs" />
<Compile Include="Controls\CoverFlow\CoverFlow.cs" />
<Compile Include="Controls\CoverFlow\CoverFlowItem.cs" />
<Compile Include="Controls\CoverView\CoverViewContent.cs" />
<Compile Include="Controls\CoverView\CoverViewItem.cs" />
<Compile Include="Controls\Other\AnimationPath.cs" />
@@ -379,6 +385,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Themes\Styles\Base\CoverFlowBaseStyle.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Themes\Styles\Base\CoverViewBaseStyle.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -415,6 +425,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Themes\Styles\CoverFlow.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="Themes\Styles\CoverView.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -0,0 +1,49 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:HandyControl.Controls">
<!--<Style x:Key="CoverFlowItemBaseStyle" TargetType="controls:CoverFlowItem">
<Setter Property="Width" Value="{Binding ItemWidth,RelativeSource={RelativeSource FindAncestor, AncestorType=controls:CoverFlow}}"/>
<Setter Property="Height" Value="{Binding ItemHeight,RelativeSource={RelativeSource FindAncestor, AncestorType=controls:CoverFlow}}"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:CoverFlowItem">
<Border BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" BorderBrush="{TemplateBinding BorderBrush}">
<ContentPresenter Margin="{TemplateBinding Padding}"/>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>-->
<Style x:Key="CoverFlowBaseStyle" TargetType="controls:CoverFlow">
<!--<Setter Property="ItemContainerStyle" Value="{StaticResource CoverFlowItemBaseStyle}"/>-->
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="controls:CoverFlow">
<Border BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}">
<Viewport3D x:Name="PART_Viewport3D">
<Viewport3D.Camera>
<PerspectiveCamera x:Name="PART_Camera" Position="0,0,3" UpDirection="0,1,0" LookDirection="0,0,-1" FieldOfView="100" NearPlaneDistance="0.125"/>
</Viewport3D.Camera>
<Viewport3D.Children>
<ModelVisual3D>
<ModelVisual3D.Content>
<DirectionalLight Color="White" Direction="1,0,-4" />
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D>
<ModelVisual3D.Content>
<DirectionalLight Color="White" Direction="-1,0,-4" />
</ModelVisual3D.Content>
</ModelVisual3D>
<ModelVisual3D x:Name="PART_VisualParent"/>
</Viewport3D.Children>
</Viewport3D>
</Border>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</ResourceDictionary>
@@ -83,7 +83,7 @@
<Grid x:Name="TemplateRoot">
<shapes:Arc ArcThickness="{TemplateBinding ArcThickness}" Stretch="None" EndAngle="360" Width="{TemplateBinding ActualWidth}" Height="{TemplateBinding ActualHeight}" Stroke="{TemplateBinding BorderBrush}" Fill="{TemplateBinding Background}" StrokeThickness="0"/>
<shapes:Arc ArcThickness="{TemplateBinding ArcThickness}" Stretch="None" Width="{TemplateBinding ActualWidth}" StrokeThickness="0" Height="{TemplateBinding ActualHeight}" x:Name="PART_Indicator" Fill="{TemplateBinding Foreground}"/>
<TextBlock Visibility="{Binding ShowText,RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="{DynamicResource PrimaryTextBrush}" Text="{TemplateBinding Text}"/>
<TextBlock Visibility="{Binding ShowText,RelativeSource={RelativeSource TemplatedParent},Converter={StaticResource Boolean2VisibilityConverter}}" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="{TemplateBinding Foreground}" Text="{TemplateBinding Text}"/>
</Grid>
</ControlTemplate>
</Setter.Value>
@@ -14,6 +14,7 @@
<Setter Property="AllowHalf" Value="{Binding AllowHalf,RelativeSource={RelativeSource FindAncestor, AncestorType=controls:Rate}}"/>
<Setter Property="AllowClear" Value="{Binding AllowClear,RelativeSource={RelativeSource FindAncestor, AncestorType=controls:Rate}}"/>
<Setter Property="Icon" Value="{Binding Icon,RelativeSource={RelativeSource FindAncestor, AncestorType=controls:Rate}}"/>
<Setter Property="IsReadOnly" Value="{Binding IsReadOnly,RelativeSource={RelativeSource FindAncestor, AncestorType=controls:Rate}}"/>
<Setter Property="Background" Value="{Binding Background,RelativeSource={RelativeSource FindAncestor, AncestorType=controls:Rate}}"/>
<Setter Property="Template">
<Setter.Value>
+10
View File
@@ -0,0 +1,10 @@
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:controls="clr-namespace:HandyControl.Controls">
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source="Base/CoverFlowBaseStyle.xaml"/>
</ResourceDictionary.MergedDictionaries>
<Style BasedOn="{StaticResource CoverFlowBaseStyle}" TargetType="controls:CoverFlow"/>
</ResourceDictionary>
+1
View File
@@ -51,6 +51,7 @@
<ResourceDictionary Source="Rate.xaml"/>
<ResourceDictionary Source="Shield.xaml"/>
<ResourceDictionary Source="CoverView.xaml"/>
<ResourceDictionary Source="CoverFlow.xaml"/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
@@ -2,6 +2,7 @@
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Media.Media3D;
namespace HandyControl.Tools
{
@@ -121,6 +122,11 @@ namespace HandyControl.Tools
/// <returns></returns>
public static double CalAngle(Point center, Point p) => Math.Atan2(p.Y - center.Y, p.X - center.X) * 180 / Math.PI;
/// <summary>
/// 判断是否是有效的双精度浮点数
/// </summary>
/// <param name="value"></param>
/// <returns></returns>
public static bool IsValidDoubleValue(object value)
{
var d = (double)value;
@@ -128,5 +134,19 @@ namespace HandyControl.Tools
return !double.IsInfinity(d);
return false;
}
/// <summary>
/// 计算法线
/// </summary>
/// <param name="p0"></param>
/// <param name="p1"></param>
/// <param name="p2"></param>
/// <returns></returns>
public static Vector3D CalNormal(Point3D p0, Point3D p1, Point3D p2)
{
var v0 = new Vector3D(p1.X - p0.X, p1.Y - p0.Y, p1.Z - p0.Z);
var v1 = new Vector3D(p2.X - p1.X, p2.Y - p1.Y, p2.Z - p1.Z);
return Vector3D.CrossProduct(v0, v1);
}
}
}
+2
View File
@@ -72,6 +72,8 @@
public static readonly string CoverViewDemoCtl = nameof(CoverViewDemoCtl);
public static readonly string CoverFlowDemoCtl = nameof(CoverFlowDemoCtl);
public static readonly string ButtonDemoCtl = nameof(ButtonDemoCtl);
public static readonly string ToggleButtonDemoCtl = nameof(ToggleButtonDemoCtl);
+2 -1
View File
@@ -38,7 +38,8 @@ var controlList = new List<string>
"RateDemoCtl",
"ShieldDemoCtl",
"WaterfallPanelDemoCtl",
"CoverViewDemoCtl"
"CoverViewDemoCtl",
"CoverFlowDemoCtl"
};
var styleList = new List<string>
{
+8
View File
@@ -139,6 +139,9 @@
<Compile Include="UserControl\Controls\CompareSliderDemoCtl.xaml.cs">
<DependentUpon>CompareSliderDemoCtl.xaml</DependentUpon>
</Compile>
<Compile Include="UserControl\Controls\CoverFlowDemoCtl.xaml.cs">
<DependentUpon>CoverFlowDemoCtl.xaml</DependentUpon>
</Compile>
<Compile Include="UserControl\Controls\CoverViewDemoCtl.xaml.cs">
<DependentUpon>CoverViewDemoCtl.xaml</DependentUpon>
</Compile>
@@ -421,6 +424,10 @@
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UserControl\Controls\CoverFlowDemoCtl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
</Page>
<Page Include="UserControl\Controls\CoverViewDemoCtl.xaml">
<SubType>Designer</SubType>
<Generator>MSBuild:Compile</Generator>
@@ -685,6 +692,7 @@
<Generator>TextTemplatingFileGenerator</Generator>
<LastGenOutput>MessageToken.cs</LastGenOutput>
</Content>
<Resource Include="Resources\Img\LeftMainContent\LinearCarousel_16x.png" />
<Resource Include="Resources\Img\Album\1.jpg" />
<Resource Include="Resources\Img\Album\10.jpg" />
<Resource Include="Resources\Img\Album\2.jpg" />
+10 -1
View File
@@ -47,7 +47,7 @@ namespace HandyControlDemo.Properties.Langs {
}
/// <summary>
/// 重写当前线程的 CurrentUICulture 属性
/// 使用此强类型资源类,为所有资源查找
/// 重写当前线程的 CurrentUICulture 属性。
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
@@ -303,6 +303,15 @@ namespace HandyControlDemo.Properties.Langs {
}
}
/// <summary>
/// 查找类似 封面流 的本地化字符串。
/// </summary>
public static string CoverFlow {
get {
return ResourceManager.GetString("CoverFlow", resourceCulture);
}
}
/// <summary>
/// 查找类似 封面视图 的本地化字符串。
/// </summary>
@@ -459,4 +459,7 @@
<data name="CoverView" xml:space="preserve">
<value>CoverView</value>
</data>
<data name="CoverFlow" xml:space="preserve">
<value>CoverFlow</value>
</data>
</root>
@@ -439,4 +439,7 @@
<data name="CoverView" xml:space="preserve">
<value>封面视图</value>
</data>
<data name="CoverFlow" xml:space="preserve">
<value>封面流</value>
</data>
</root>
Binary file not shown.

After

Width:  |  Height:  |  Size: 184 B

@@ -0,0 +1,9 @@
<UserControl x:Class="HandyControlDemo.UserControl.CoverFlowDemoCtl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:controls="clr-namespace:HandyControl.Controls;assembly=HandyControl"
Background="{DynamicResource RegionBrush}">
<controls:TransitioningContentControl>
<controls:CoverFlow x:Name="CoverFlowMain" Margin="32" Width="500" Height="300"/>
</controls:TransitioningContentControl>
</UserControl>
@@ -0,0 +1,28 @@
using System;
using System.Collections.Generic;
namespace HandyControlDemo.UserControl
{
public partial class CoverFlowDemoCtl
{
public CoverFlowDemoCtl()
{
InitializeComponent();
CoverFlowMain.AddRange(new List<Uri>
{
new Uri(@"pack://application:,,,/Resources/Img/Album/1.jpg"),
new Uri(@"pack://application:,,,/Resources/Img/Album/2.jpg"),
new Uri(@"pack://application:,,,/Resources/Img/Album/3.jpg"),
new Uri(@"pack://application:,,,/Resources/Img/Album/4.jpg"),
new Uri(@"pack://application:,,,/Resources/Img/Album/5.jpg"),
new Uri(@"pack://application:,,,/Resources/Img/Album/6.jpg"),
new Uri(@"pack://application:,,,/Resources/Img/Album/7.jpg"),
new Uri(@"pack://application:,,,/Resources/Img/Album/8.jpg"),
new Uri(@"pack://application:,,,/Resources/Img/Album/9.jpg"),
new Uri(@"pack://application:,,,/Resources/Img/Album/10.jpg")
});
CoverFlowMain.JumpTo(2);
}
}
}
@@ -7,7 +7,7 @@
<StackPanel Margin="32" HorizontalAlignment="Center" VerticalAlignment="Center" Width="170">
<controls:Rate Value="2"/>
<controls:Rate Value="5" Count="6" Margin="0,16,0,0" Foreground="{DynamicResource SuccessBrush}"/>
<controls:Rate DefaultValue="3" AllowHalf="True" Margin="0,16,0,0" Foreground="{DynamicResource WarningBrush}"/>
<controls:Rate DefaultValue="3" IsReadOnly="True" AllowHalf="True" Margin="0,16,0,0" Foreground="{DynamicResource WarningBrush}"/>
<controls:Rate DefaultValue="1" AllowClear="False" AllowHalf="True" Margin="0,16,0,0" Foreground="{DynamicResource DangerBrush}" Icon="{StaticResource LoveGeometry}"/>
<controls:Rate Value="4.5" AllowHalf="True" ShowText="True" Margin="0,16,0,0" Foreground="{DynamicResource DangerBrush}" Icon="{StaticResource LoveGeometry}"/>
</StackPanel>
@@ -190,7 +190,7 @@
<Image Source="../../Resources/Img/LeftMainContent/DatePicker_16x.png"/>
</controls:EdgeElement.LeftContent>
</ListBoxItem>
<ListBoxItem Style="{StaticResource ListBoxItemNew}" Tag="{x:Static data:MessageToken.FlipClockDemoCtl}" Content="{x:Static langs:Lang.FlipClock}">
<ListBoxItem Tag="{x:Static data:MessageToken.FlipClockDemoCtl}" Content="{x:Static langs:Lang.FlipClock}">
<controls:EdgeElement.LeftContent>
<Image Source="../../Resources/Img/LeftMainContent/FlipVertical_16x.png"/>
</controls:EdgeElement.LeftContent>
@@ -240,6 +240,11 @@
<Image Source="../../Resources/Img/LeftMainContent/DetailDataView_16x.png"/>
</controls:EdgeElement.LeftContent>
</ListBoxItem>
<ListBoxItem Style="{StaticResource ListBoxItemNew}" Tag="{x:Static data:MessageToken.CoverFlowDemoCtl}" Content="{x:Static langs:Lang.CoverFlow}">
<controls:EdgeElement.LeftContent>
<Image Source="../../Resources/Img/LeftMainContent/LinearCarousel_16x.png"/>
</controls:EdgeElement.LeftContent>
</ListBoxItem>
<ListBoxItem Tag="{x:Static data:MessageToken.CircleProgressBarDemoCtl}" Content="{x:Static langs:Lang.CircleProgressBar}">
<controls:EdgeElement.LeftContent>
<Image Source="../../Resources/Img/LeftMainContent/ShapeArcRing_16x.png"/>
@@ -310,7 +315,7 @@
<Image Source="../../Resources/Img/LeftMainContent/ScrollBox_16x.png"/>
</controls:EdgeElement.LeftContent>
</ListBoxItem>
<ListBoxItem Style="{StaticResource ListBoxItemNew}" Tag="{x:Static data:MessageToken.WindowDemoCtl}" Content="{x:Static langs:Lang.Window}">
<ListBoxItem Tag="{x:Static data:MessageToken.WindowDemoCtl}" Content="{x:Static langs:Lang.Window}">
<controls:EdgeElement.LeftContent>
<Image Source="../../Resources/Img/LeftMainContent/WindowsForm_16x.png"/>
</controls:EdgeElement.LeftContent>
+6 -2
View File
@@ -6,6 +6,10 @@
## Latest examples
### CoverFlow
![CoverFlow](https://raw.githubusercontent.com/NaBian/HandyControl/master/Resources/CoverFlow.gif)
### CoverView
![CoverView](https://raw.githubusercontent.com/NaBian/HandyControl/master/Resources/CoverView.gif)
@@ -22,12 +26,12 @@
![BlurWindow](https://raw.githubusercontent.com/NaBian/HandyControl/master/Resources/BlurWindow.png)
## History publication
### FlipClock
![FlipClock](https://raw.githubusercontent.com/NaBian/HandyControl/master/Resources/FlipClock.gif)
## History publication
### Shield
![Shield](https://raw.githubusercontent.com/NaBian/HandyControl/master/Resources/Shield.png)
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.1 MiB