Synchronize the Net40
This commit is contained in:
1 parent
b3c3173c46
commit
ab6e2efe21
87 files changed
+2743
-349
No files matched your search
@@ -1,6 +1,5 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
using HandyControl.Data;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
|
||||
@@ -29,11 +29,38 @@ namespace HandyControl.Controls
|
||||
|
||||
if (_isMouseLeftButtonDown)
|
||||
{
|
||||
RaiseEvent(new RoutedEventArgs(SelectedEvent, this));
|
||||
if (SelfManage)
|
||||
{
|
||||
if (!IsSelected)
|
||||
{
|
||||
IsSelected = true;
|
||||
OnSelected(new RoutedEventArgs(SelectedEvent, this));
|
||||
}
|
||||
else if (CanDeselect)
|
||||
{
|
||||
IsSelected = false;
|
||||
OnSelected(new RoutedEventArgs(DeselectedEvent, this));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (CanDeselect)
|
||||
{
|
||||
OnSelected(IsSelected
|
||||
? new RoutedEventArgs(DeselectedEvent, this)
|
||||
: new RoutedEventArgs(SelectedEvent, this));
|
||||
}
|
||||
else
|
||||
{
|
||||
OnSelected(new RoutedEventArgs(SelectedEvent, this));
|
||||
}
|
||||
}
|
||||
_isMouseLeftButtonDown = false;
|
||||
}
|
||||
}
|
||||
|
||||
protected virtual void OnSelected(RoutedEventArgs e) => RaiseEvent(e);
|
||||
|
||||
public static readonly DependencyProperty IsSelectedProperty = DependencyProperty.Register(
|
||||
"IsSelected", typeof(bool), typeof(SelectableItem), new PropertyMetadata(ValueBoxes.FalseBox));
|
||||
|
||||
@@ -43,6 +70,24 @@ namespace HandyControl.Controls
|
||||
set => SetValue(IsSelectedProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty SelfManageProperty = DependencyProperty.Register(
|
||||
"SelfManage", typeof(bool), typeof(SelectableItem), new PropertyMetadata(ValueBoxes.FalseBox));
|
||||
|
||||
public bool SelfManage
|
||||
{
|
||||
get => (bool)GetValue(SelfManageProperty);
|
||||
set => SetValue(SelfManageProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty CanDeselectProperty = DependencyProperty.Register(
|
||||
"CanDeselect", typeof(bool), typeof(SelectableItem), new PropertyMetadata(ValueBoxes.FalseBox));
|
||||
|
||||
public bool CanDeselect
|
||||
{
|
||||
get => (bool)GetValue(CanDeselectProperty);
|
||||
set => SetValue(CanDeselectProperty, value);
|
||||
}
|
||||
|
||||
public static readonly RoutedEvent SelectedEvent =
|
||||
EventManager.RegisterRoutedEvent("Selected", RoutingStrategy.Bubble,
|
||||
typeof(RoutedEventHandler), typeof(SelectableItem));
|
||||
@@ -52,5 +97,15 @@ namespace HandyControl.Controls
|
||||
add => AddHandler(SelectedEvent, value);
|
||||
remove => RemoveHandler(SelectedEvent, value);
|
||||
}
|
||||
|
||||
public static readonly RoutedEvent DeselectedEvent =
|
||||
EventManager.RegisterRoutedEvent("Deselected", RoutingStrategy.Bubble,
|
||||
typeof(RoutedEventHandler), typeof(SelectableItem));
|
||||
|
||||
public event RoutedEventHandler Deselected
|
||||
{
|
||||
add => AddHandler(DeselectedEvent, value);
|
||||
remove => RemoveHandler(DeselectedEvent, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.ComponentModel;
|
||||
using System.Windows;
|
||||
@@ -25,25 +26,35 @@ namespace HandyControl.Controls
|
||||
"ItemContainerStyle", typeof(Style), typeof(SimpleItemsControl),
|
||||
new PropertyMetadata(default(Style), OnItemContainerStyleChanged));
|
||||
|
||||
public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register(
|
||||
"ItemsSource", typeof(IEnumerable), typeof(SimpleItemsControl),
|
||||
new PropertyMetadata(default(IEnumerable), OnItemsSourceChanged));
|
||||
|
||||
public SimpleItemsControl()
|
||||
{
|
||||
var items = new ObservableCollection<object>();
|
||||
items.CollectionChanged += OnItemsCollectionChanged;
|
||||
items.CollectionChanged += OnItemsChanged;
|
||||
Items = items;
|
||||
}
|
||||
|
||||
public IEnumerable ItemsSource
|
||||
{
|
||||
get => (IEnumerable)GetValue(ItemsSourceProperty);
|
||||
set => SetValue(ItemsSourceProperty, value);
|
||||
}
|
||||
|
||||
[Bindable(true)]
|
||||
[Category("Content")]
|
||||
public Style ItemContainerStyle
|
||||
{
|
||||
get => (Style) GetValue(ItemContainerStyleProperty);
|
||||
get => (Style)GetValue(ItemContainerStyleProperty);
|
||||
set => SetValue(ItemContainerStyleProperty, value);
|
||||
}
|
||||
|
||||
[Bindable(true)]
|
||||
public DataTemplate ItemTemplate
|
||||
{
|
||||
get => (DataTemplate) GetValue(ItemTemplateProperty);
|
||||
get => (DataTemplate)GetValue(ItemTemplateProperty);
|
||||
set => SetValue(ItemTemplateProperty, value);
|
||||
}
|
||||
|
||||
@@ -53,6 +64,15 @@ namespace HandyControl.Controls
|
||||
|
||||
internal Panel ItemsHost { get; set; }
|
||||
|
||||
private static void OnItemsSourceChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
((SimpleItemsControl)d).OnItemsSourceChanged((IEnumerable)e.OldValue, (IEnumerable)e.NewValue);
|
||||
}
|
||||
|
||||
protected virtual void OnItemsSourceChanged(IEnumerable oldValue, IEnumerable newValue)
|
||||
{
|
||||
}
|
||||
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
ItemsHost?.Children.Clear();
|
||||
@@ -63,7 +83,7 @@ namespace HandyControl.Controls
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private void OnItemsCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
protected virtual void OnItemsChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
Refresh();
|
||||
UpdateItems();
|
||||
@@ -89,16 +109,14 @@ namespace HandyControl.Controls
|
||||
}
|
||||
|
||||
private static void OnItemTemplateChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var target = d as SimpleItemsControl;
|
||||
target?.Refresh();
|
||||
}
|
||||
=> (d as SimpleItemsControl)?.OnItemTemplateChanged(e);
|
||||
|
||||
protected virtual void OnItemTemplateChanged(DependencyPropertyChangedEventArgs e) => Refresh();
|
||||
|
||||
private static void OnItemContainerStyleChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
var target = d as SimpleItemsControl;
|
||||
target?.Refresh();
|
||||
}
|
||||
=> (d as SimpleItemsControl)?.OnItemContainerStyleChanged(e);
|
||||
|
||||
protected virtual void OnItemContainerStyleChanged(DependencyPropertyChangedEventArgs e) => Refresh();
|
||||
|
||||
protected virtual void Refresh()
|
||||
{
|
||||
@@ -128,7 +146,6 @@ namespace HandyControl.Controls
|
||||
|
||||
protected virtual void UpdateItems()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,27 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using HandyControl.Data;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class ProgressButton : ToggleButton
|
||||
{
|
||||
public static readonly DependencyProperty ProgressStyleProperty = DependencyProperty.Register(
|
||||
"ProgressStyle", typeof(Style), typeof(ProgressButton), new PropertyMetadata(default(Style)));
|
||||
|
||||
public Style ProgressStyle
|
||||
{
|
||||
get => (Style) GetValue(ProgressStyleProperty);
|
||||
set => SetValue(ProgressStyleProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ProgressProperty = DependencyProperty.Register(
|
||||
"Progress", typeof(double), typeof(ProgressButton), new PropertyMetadata(ValueBoxes.Double0Box));
|
||||
|
||||
public double Progress
|
||||
{
|
||||
get => (double) GetValue(ProgressProperty);
|
||||
set => SetValue(ProgressProperty, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,305 @@
|
||||
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 int _jumpToIndex = -1;
|
||||
|
||||
/// <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;
|
||||
|
||||
UpdateShowRange();
|
||||
if (_jumpToIndex > 0)
|
||||
{
|
||||
PageIndex = _jumpToIndex;
|
||||
_jumpToIndex = -1;
|
||||
}
|
||||
_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);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 添加一项资源
|
||||
/// </summary>
|
||||
/// <param name="uriString"></param>
|
||||
public void Add(string uriString) => _uriList.Add(_uriList.Count, new Uri(uriString));
|
||||
|
||||
/// <summary>
|
||||
/// 添加一项资源
|
||||
/// </summary>
|
||||
/// <param name="uri"></param>
|
||||
public void Add(Uri uri) => _uriList.Add(_uriList.Count, uri);
|
||||
|
||||
/// <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,165 @@
|
||||
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) => 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;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,216 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Data;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Tools;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class CoverView : RegularItemsControl
|
||||
{
|
||||
private readonly CoverViewContent _viewContent;
|
||||
|
||||
private CoverViewItem _selectedItem;
|
||||
|
||||
public CoverView()
|
||||
{
|
||||
_viewContent = new CoverViewContent();
|
||||
|
||||
AddHandler(SelectableItem.SelectedEvent, new RoutedEventHandler(CoverViewItem_OnSelected));
|
||||
_viewContent.SetBinding(CoverViewContent.ContentHeightProperty, new Binding(ItemContentHeightProperty.Name) { Source = this });
|
||||
_viewContent.SetBinding(WidthProperty, new Binding(ActualWidthProperty.Name) { Source = this });
|
||||
}
|
||||
|
||||
private void CoverViewItem_OnSelected(object sender, RoutedEventArgs e)
|
||||
{
|
||||
if (e.OriginalSource is CoverViewItem item)
|
||||
{
|
||||
if (_selectedItem == null)
|
||||
{
|
||||
item.IsSelected = true;
|
||||
_selectedItem = item;
|
||||
if (_viewContent != null)
|
||||
{
|
||||
_viewContent.Content = item.Content;
|
||||
UpdateCoverViewContent(true);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (!Equals(_selectedItem, item))
|
||||
{
|
||||
_selectedItem.IsSelected = false;
|
||||
item.IsSelected = true;
|
||||
_selectedItem = item;
|
||||
if (_viewContent != null)
|
||||
{
|
||||
_viewContent.Content = item.Content;
|
||||
UpdateCoverViewContent(true);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
if (_viewContent != null)
|
||||
{
|
||||
_viewContent.Content = null;
|
||||
UpdateCoverViewContent(false);
|
||||
}
|
||||
_selectedItem.IsSelected = false;
|
||||
_selectedItem = null;
|
||||
}
|
||||
}
|
||||
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
|
||||
if (_viewContent.Style == null)
|
||||
{
|
||||
_viewContent.Style = CoverViewContentStyle;
|
||||
}
|
||||
|
||||
if (_selectedItem != null)
|
||||
{
|
||||
UpdateCoverViewContent(_selectedItem != null);
|
||||
}
|
||||
}
|
||||
|
||||
protected override DependencyObject GetContainerForItemOverride() => new CoverViewItem();
|
||||
|
||||
protected override bool IsItemItsOwnContainerOverride(object item) => item is CoverViewItem;
|
||||
|
||||
public static readonly DependencyProperty CoverViewContentStyleProperty = DependencyProperty.Register(
|
||||
"CoverViewContentStyle", typeof(Style), typeof(CoverView), new PropertyMetadata(default(Style)));
|
||||
|
||||
public Style CoverViewContentStyle
|
||||
{
|
||||
get => (Style)GetValue(CoverViewContentStyleProperty);
|
||||
set => SetValue(CoverViewContentStyleProperty, value);
|
||||
}
|
||||
|
||||
internal static readonly DependencyProperty GroupsProperty = DependencyProperty.Register(
|
||||
"Groups", typeof(int), typeof(CoverView),
|
||||
new FrameworkPropertyMetadata(ValueBoxes.Int5Box, FrameworkPropertyMetadataOptions.AffectsMeasure,
|
||||
OnGroupsChanged), IsGroupsValid);
|
||||
|
||||
internal static void OnGroupsChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is CoverView ctl)
|
||||
{
|
||||
ctl.UpdateCoverViewContent(ctl._viewContent.IsOpen);
|
||||
}
|
||||
}
|
||||
|
||||
private static bool IsGroupsValid(object value)
|
||||
{
|
||||
var v = (int)value;
|
||||
return v >= 1;
|
||||
}
|
||||
|
||||
public int Groups
|
||||
{
|
||||
get => (int)GetValue(GroupsProperty);
|
||||
set => SetValue(GroupsProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ItemContentHeightProperty = DependencyProperty.Register(
|
||||
"ItemContentHeight", typeof(double), typeof(CoverView), new PropertyMetadata(ValueBoxes.Double300Box),
|
||||
value => ValidateHelper.IsInRangeOfPosDouble(value, true));
|
||||
|
||||
public double ItemContentHeight
|
||||
{
|
||||
get => (double)GetValue(ItemContentHeightProperty);
|
||||
set => SetValue(ItemContentHeightProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ItemContentHeightFixedProperty = DependencyProperty.Register(
|
||||
"ItemContentHeightFixed", typeof(bool), typeof(CoverView), new PropertyMetadata(ValueBoxes.TrueBox));
|
||||
|
||||
public bool ItemContentHeightFixed
|
||||
{
|
||||
get => (bool)GetValue(ItemContentHeightFixedProperty);
|
||||
set => SetValue(ItemContentHeightFixedProperty, value);
|
||||
}
|
||||
|
||||
protected override void OnRenderSizeChanged(SizeChangedInfo sizeInfo)
|
||||
{
|
||||
base.OnRenderSizeChanged(sizeInfo);
|
||||
|
||||
Groups = (int)(sizeInfo.NewSize.Width / (ItemWidth + ItemMargin.Left + ItemMargin.Right));
|
||||
}
|
||||
|
||||
protected override void Refresh()
|
||||
{
|
||||
if (ItemsHost == null) return;
|
||||
|
||||
ItemsHost.Children.Clear();
|
||||
var index = 0;
|
||||
foreach (var item in Items)
|
||||
{
|
||||
DependencyObject container;
|
||||
if (IsItemItsOwnContainerOverride(item))
|
||||
{
|
||||
container = item as DependencyObject;
|
||||
}
|
||||
else
|
||||
{
|
||||
container = GetContainerForItemOverride();
|
||||
PrepareContainerForItemOverride(container, item);
|
||||
}
|
||||
|
||||
if (container is CoverViewItem element)
|
||||
{
|
||||
element.Index = index++;
|
||||
element.Style = ItemContainerStyle;
|
||||
ItemsHost.Children.Add(element);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 更新内容视图
|
||||
/// </summary>
|
||||
private void UpdateCoverViewContent(bool isOpen)
|
||||
{
|
||||
if (_selectedItem == null) return;
|
||||
|
||||
ItemsHost.Children.Remove(_viewContent);
|
||||
|
||||
if (!ItemContentHeightFixed)
|
||||
{
|
||||
_viewContent.ManualHeight = 0;
|
||||
if (_viewContent.Content is FrameworkElement element)
|
||||
{
|
||||
element.Arrange(new Rect(new Size(double.MaxValue, double.MaxValue)));
|
||||
_viewContent.ManualHeight = element.ActualHeight;
|
||||
}
|
||||
}
|
||||
|
||||
var total = Items.Count + 1;
|
||||
var totalRow = total / Groups + (total % Groups > 0 ? 1 : 0);
|
||||
if (total <= Groups)
|
||||
{
|
||||
ItemsHost.Children.Add(_viewContent);
|
||||
}
|
||||
else
|
||||
{
|
||||
var row = _selectedItem.Index / Groups + 1;
|
||||
if (row == totalRow)
|
||||
{
|
||||
ItemsHost.Children.Add(_viewContent);
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemsHost.Children.Insert(row * Groups, _viewContent);
|
||||
}
|
||||
}
|
||||
|
||||
_viewContent.UpdatePosition(_selectedItem.Index, Groups, _selectedItem.DesiredSize.Width);
|
||||
if (_viewContent.CanSwitch)
|
||||
{
|
||||
_viewContent.IsOpen = isOpen;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,122 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using HandyControl.Data;
|
||||
using HandyControl.Expression.Drawing;
|
||||
using HandyControl.Tools;
|
||||
using HandyControl.Tools.Extension;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
[TemplatePart(Name = ElementTriangle, Type = typeof(FrameworkElement))]
|
||||
[TemplatePart(Name = ElementContent, Type = typeof(FrameworkElement))]
|
||||
internal class CoverViewContent : ContentControl
|
||||
{
|
||||
private const string ElementTriangle = "PART_Triangle";
|
||||
|
||||
private const string ElementContent = "PART_Content";
|
||||
|
||||
private FrameworkElement _triangle;
|
||||
|
||||
private FrameworkElement _content;
|
||||
|
||||
internal bool WaitForUpdate { get; set; }
|
||||
|
||||
private int _index;
|
||||
|
||||
private int _groups;
|
||||
|
||||
private double _itemWidth;
|
||||
|
||||
internal bool CanSwitch { get; set; } = true;
|
||||
|
||||
private bool _isOpen;
|
||||
|
||||
internal bool IsOpen
|
||||
{
|
||||
get => _isOpen;
|
||||
set
|
||||
{
|
||||
if (_isOpen == value) return;
|
||||
_isOpen = value;
|
||||
OpenSwitch(value);
|
||||
}
|
||||
}
|
||||
|
||||
internal static readonly DependencyProperty ManualHeightProperty = DependencyProperty.Register(
|
||||
"ManualHeight", typeof(double), typeof(CoverViewContent), new PropertyMetadata(default(double)), value => ValidateHelper.IsInRangeOfPosDouble(value, true));
|
||||
|
||||
internal double ManualHeight
|
||||
{
|
||||
get => (double)GetValue(ManualHeightProperty);
|
||||
set => SetValue(ManualHeightProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty ContentHeightProperty = DependencyProperty.Register(
|
||||
"ContentHeight", typeof(double), typeof(CoverViewContent), new PropertyMetadata(ValueBoxes.Double300Box),
|
||||
value => ValidateHelper.IsInRangeOfPosDouble(value, true));
|
||||
|
||||
public double ContentHeight
|
||||
{
|
||||
get => (double)GetValue(ContentHeightProperty);
|
||||
set => SetValue(ContentHeightProperty, value);
|
||||
}
|
||||
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
base.OnApplyTemplate();
|
||||
|
||||
_triangle = GetTemplateChild(ElementTriangle) as FrameworkElement;
|
||||
_content = GetTemplateChild(ElementContent) as FrameworkElement;
|
||||
|
||||
if (WaitForUpdate)
|
||||
{
|
||||
_triangle.BeginAnimation(MarginProperty, AnimationHelper.CreateAnimation(new Thickness((_index % _groups + .5) * _itemWidth - _triangle.Width / 2, 0, 0, 0)));
|
||||
OpenSwitch(_isOpen);
|
||||
WaitForUpdate = false;
|
||||
}
|
||||
}
|
||||
|
||||
internal void UpdatePosition(int index, int groups, double itemWidth)
|
||||
{
|
||||
if (_triangle == null)
|
||||
{
|
||||
_index = index;
|
||||
_groups = groups;
|
||||
_itemWidth = itemWidth;
|
||||
WaitForUpdate = true;
|
||||
return;
|
||||
}
|
||||
_triangle.BeginAnimation(MarginProperty, AnimationHelper.CreateAnimation(new Thickness((index % groups + .5) * itemWidth - _triangle.Width / 2, 0, 0, 0)));
|
||||
if (IsOpen)
|
||||
{
|
||||
if (ManualHeight > 0 && !MathHelper.AreClose(ManualHeight, ContentHeight))
|
||||
{
|
||||
_content.BeginAnimation(HeightProperty, AnimationHelper.CreateAnimation(ManualHeight));
|
||||
}
|
||||
else
|
||||
{
|
||||
_content.BeginAnimation(HeightProperty, AnimationHelper.CreateAnimation(ContentHeight));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void OpenSwitch(bool isOpen)
|
||||
{
|
||||
if (_content == null) return;
|
||||
var animation = AnimationHelper.CreateAnimation(isOpen ? ManualHeight > 0 ? ManualHeight : ContentHeight : 0);
|
||||
_triangle.Show(false);
|
||||
this.Show(true);
|
||||
animation.Completed += (s, e) =>
|
||||
{
|
||||
CanSwitch = true;
|
||||
this.Show(IsOpen);
|
||||
if (IsOpen)
|
||||
{
|
||||
_triangle.Show(true);
|
||||
}
|
||||
};
|
||||
CanSwitch = false;
|
||||
_content.BeginAnimation(HeightProperty, animation);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class CoverViewItem : HeaderedSelectableItem
|
||||
{
|
||||
internal int Index { get; set; }
|
||||
}
|
||||
}
|
||||
@@ -39,6 +39,7 @@ namespace HandyControl.Controls
|
||||
if (_textBox != null)
|
||||
{
|
||||
_textBox.TextChanged -= TextBox_TextChanged;
|
||||
_textBox.KeyDown -= TextBox_KeyDown;
|
||||
}
|
||||
|
||||
base.OnApplyTemplate();
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
using System;
|
||||
using System.Windows;
|
||||
using HandyControl.Data;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class ChatBubble : SelectableItem
|
||||
{
|
||||
public static readonly DependencyProperty RoleProperty = DependencyProperty.Register(
|
||||
"Role", typeof(ChatRoleType), typeof(ChatBubble), new PropertyMetadata(default(ChatRoleType)));
|
||||
|
||||
public ChatRoleType Role
|
||||
{
|
||||
get => (ChatRoleType)GetValue(RoleProperty);
|
||||
set => SetValue(RoleProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty TypeProperty = DependencyProperty.Register(
|
||||
"Type", typeof(ChatMessageType), typeof(ChatBubble), new PropertyMetadata(default(ChatMessageType)));
|
||||
|
||||
public ChatMessageType Type
|
||||
{
|
||||
get => (ChatMessageType)GetValue(TypeProperty);
|
||||
set => SetValue(TypeProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsReadProperty = DependencyProperty.Register(
|
||||
"IsRead", typeof(bool), typeof(ChatBubble), new PropertyMetadata(ValueBoxes.FalseBox));
|
||||
|
||||
public bool IsRead
|
||||
{
|
||||
get => (bool)GetValue(IsReadProperty);
|
||||
set => SetValue(IsReadProperty, value);
|
||||
}
|
||||
|
||||
public static void SetMaxWidth(DependencyObject element, double value)
|
||||
=> element.SetValue(MaxWidthProperty, value);
|
||||
|
||||
public static double GetMaxWidth(DependencyObject element)
|
||||
=> (double)element.GetValue(MaxWidthProperty);
|
||||
|
||||
public Action<object> ReadAction { get; set; }
|
||||
|
||||
protected override void OnSelected(RoutedEventArgs e)
|
||||
{
|
||||
base.OnSelected(e);
|
||||
|
||||
IsRead = true;
|
||||
ReadAction?.Invoke(Content);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,223 @@
|
||||
using System.Collections;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.Collections.Specialized;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
using HandyControl.Interactivity;
|
||||
using HandyControl.Tools.Extension;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
/// <summary>
|
||||
/// 穿梭框
|
||||
/// </summary>
|
||||
[TemplatePart(Name = ElementItemsOrigin, Type = typeof(SimpleItemsControl))]
|
||||
[TemplatePart(Name = ElementItemsSelected, Type = typeof(SimpleItemsControl))]
|
||||
public class Transfer : SimpleItemsControl
|
||||
{
|
||||
private const string ElementItemsOrigin = "PART_ItemsOrigin";
|
||||
|
||||
private const string ElementItemsSelected = "PART_ItemsSelected";
|
||||
|
||||
private readonly Dictionary<object, TransferEntry> _entryDic = new Dictionary<object, TransferEntry>();
|
||||
|
||||
private SimpleItemsControl _itemsOrigin;
|
||||
|
||||
private SimpleItemsControl _itemsSelected;
|
||||
|
||||
private IEnumerable _itemsSourceInternal;
|
||||
|
||||
public static readonly RoutedEvent SelectionChangedEvent =
|
||||
EventManager.RegisterRoutedEvent("SelectionChanged", RoutingStrategy.Bubble,
|
||||
typeof(SelectionChangedEventHandler), typeof(Transfer));
|
||||
|
||||
public event SelectionChangedEventHandler SelectionChanged
|
||||
{
|
||||
add => AddHandler(SelectionChangedEvent, value);
|
||||
remove => RemoveHandler(SelectionChangedEvent, value);
|
||||
}
|
||||
|
||||
private static readonly DependencyPropertyKey SelectedItemsPropertyKey =
|
||||
DependencyProperty.RegisterReadOnly(
|
||||
"SelectedItems",
|
||||
typeof(IList),
|
||||
typeof(Transfer),
|
||||
new FrameworkPropertyMetadata(default(IList)));
|
||||
|
||||
public static readonly DependencyProperty SelectedItemsProperty = SelectedItemsPropertyKey.DependencyProperty;
|
||||
|
||||
public IList SelectedItems
|
||||
{
|
||||
get => (IList)GetValue(SelectedItemsProperty);
|
||||
set => SetValue(SelectedItemsProperty, value);
|
||||
}
|
||||
|
||||
public Transfer()
|
||||
{
|
||||
CommandBindings.Add(new CommandBinding(ControlCommands.Selected, SelectItems));
|
||||
CommandBindings.Add(new CommandBinding(ControlCommands.Cancel, DeselectItems));
|
||||
|
||||
SetValue(SelectedItemsPropertyKey, new ObservableCollection<object>());
|
||||
}
|
||||
|
||||
public override void OnApplyTemplate()
|
||||
{
|
||||
_itemsOrigin?.ItemsHost.Children.Clear();
|
||||
_itemsSelected?.ItemsHost.Children.Clear();
|
||||
|
||||
_itemsOrigin = GetTemplateChild(ElementItemsOrigin) as SimpleItemsControl;
|
||||
_itemsSelected = GetTemplateChild(ElementItemsSelected) as SimpleItemsControl;
|
||||
|
||||
Refresh();
|
||||
}
|
||||
|
||||
private void AddItem(object item)
|
||||
{
|
||||
var origin = new TransferItem
|
||||
{
|
||||
Content = item
|
||||
};
|
||||
var selected = new TransferItem
|
||||
{
|
||||
Content = item,
|
||||
IsOrigin = false
|
||||
};
|
||||
var entry = new TransferEntry
|
||||
{
|
||||
OriginItem = origin,
|
||||
SelectedItem = selected
|
||||
};
|
||||
_entryDic.Add(item, entry);
|
||||
_itemsOrigin.Items.Add(origin);
|
||||
_itemsSelected.Items.Add(selected);
|
||||
}
|
||||
|
||||
private void RemoveItem(object item)
|
||||
{
|
||||
if (_entryDic.TryGetValue(item, out var entry))
|
||||
{
|
||||
_itemsOrigin.Items.Remove(entry.OriginItem);
|
||||
_itemsSelected.Items.Remove(entry.SelectedItem);
|
||||
_entryDic.Remove(item);
|
||||
}
|
||||
}
|
||||
|
||||
private void ClearItems()
|
||||
{
|
||||
_entryDic.Clear();
|
||||
_itemsOrigin.Items.Clear();
|
||||
_itemsSelected.Items.Clear();
|
||||
}
|
||||
|
||||
protected override void OnItemsSourceChanged(IEnumerable oldValue, IEnumerable newValue)
|
||||
{
|
||||
if (_itemsSourceInternal != null)
|
||||
{
|
||||
if (_itemsSourceInternal is INotifyCollectionChanged s)
|
||||
{
|
||||
s.CollectionChanged -= InternalCollectionChanged;
|
||||
}
|
||||
|
||||
ClearItems();
|
||||
}
|
||||
_itemsSourceInternal = newValue;
|
||||
if (_itemsSourceInternal != null)
|
||||
{
|
||||
if (_itemsSourceInternal is INotifyCollectionChanged s)
|
||||
{
|
||||
s.CollectionChanged += InternalCollectionChanged;
|
||||
}
|
||||
foreach (var item in _itemsSourceInternal)
|
||||
{
|
||||
AddItem(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void InternalCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
if (e.OldItems != null)
|
||||
{
|
||||
foreach (var item in e.OldItems)
|
||||
{
|
||||
RemoveItem(item);
|
||||
}
|
||||
}
|
||||
if (e.NewItems != null)
|
||||
{
|
||||
foreach (var item in e.NewItems)
|
||||
{
|
||||
AddItem(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override DependencyObject GetContainerForItemOverride() => new TransferItem();
|
||||
|
||||
protected override bool IsItemItsOwnContainerOverride(object item) => item is TransferItem;
|
||||
|
||||
private void SelectItems(object sender, ExecutedRoutedEventArgs e)
|
||||
{
|
||||
var list = _entryDic.Where(item => item.Value.OriginItem.IsSelected).ToList();
|
||||
list.Do(item => item.Value.StatusSwitch(true)).Do(item => SelectedItems.Add(item.Key));
|
||||
RaiseEvent(new SelectionChangedEventArgs(SelectionChangedEvent, new List<object>(), list));
|
||||
}
|
||||
|
||||
private void DeselectItems(object sender, ExecutedRoutedEventArgs e)
|
||||
{
|
||||
var list = _entryDic.Where(item => item.Value.SelectedItem.IsSelected).ToList();
|
||||
list.Do(item => item.Value.StatusSwitch(false)).Do(item => SelectedItems.Remove(item.Key));
|
||||
RaiseEvent(new SelectionChangedEventArgs(SelectionChangedEvent, list, new List<object>()));
|
||||
}
|
||||
|
||||
protected override void OnItemsChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void OnItemTemplateChanged(DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void OnItemContainerStyleChanged(DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void Refresh()
|
||||
{
|
||||
if (_entryDic.Count > 0)
|
||||
{
|
||||
_entryDic.Select(item => item.Value.OriginItem).Do(item => _itemsOrigin.Items.Add(item));
|
||||
_entryDic.Select(item => item.Value.SelectedItem).Do(item => _itemsSelected.Items.Add(item));
|
||||
}
|
||||
}
|
||||
|
||||
private struct TransferEntry
|
||||
{
|
||||
public TransferItem OriginItem { get; set; }
|
||||
|
||||
public TransferItem SelectedItem { get; set; }
|
||||
|
||||
public void StatusSwitch(bool isTransferred)
|
||||
{
|
||||
if (isTransferred)
|
||||
{
|
||||
OriginItem.IsTransferred = true;
|
||||
SelectedItem.IsTransferred = true;
|
||||
OriginItem.IsSelected = false;
|
||||
}
|
||||
else
|
||||
{
|
||||
OriginItem.IsTransferred = false;
|
||||
SelectedItem.IsTransferred = false;
|
||||
SelectedItem.IsSelected = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,54 @@
|
||||
using System.Collections.Specialized;
|
||||
using System.Windows;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class TransferGroup : SimpleItemsControl
|
||||
{
|
||||
protected override void Refresh()
|
||||
{
|
||||
if (Items.Count > 0)
|
||||
{
|
||||
foreach (FrameworkElement item in Items)
|
||||
{
|
||||
item.Style = ItemContainerStyle;
|
||||
ItemsHost.Children.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
protected override void OnItemTemplateChanged(DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override void OnItemContainerStyleChanged(DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
protected override DependencyObject GetContainerForItemOverride() => new TransferItem();
|
||||
|
||||
protected override bool IsItemItsOwnContainerOverride(object item) => item is TransferItem;
|
||||
|
||||
protected override void OnItemsChanged(object sender, NotifyCollectionChangedEventArgs e)
|
||||
{
|
||||
if (ItemsHost == null) return;
|
||||
if (e.OldItems != null)
|
||||
{
|
||||
foreach (FrameworkElement item in e.OldItems)
|
||||
{
|
||||
ItemsHost.Children.Remove(item);
|
||||
}
|
||||
}
|
||||
if (e.NewItems != null)
|
||||
{
|
||||
foreach (FrameworkElement item in e.NewItems)
|
||||
{
|
||||
item.Style = ItemContainerStyle;
|
||||
ItemsHost.Children.Add(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
using System.Windows;
|
||||
using HandyControl.Data;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class TransferItem : SelectableItem
|
||||
{
|
||||
public static readonly DependencyProperty IsTransferredProperty = DependencyProperty.Register(
|
||||
"IsTransferred", typeof(bool), typeof(TransferItem), new PropertyMetadata(ValueBoxes.FalseBox));
|
||||
|
||||
public bool IsTransferred
|
||||
{
|
||||
get => (bool)GetValue(IsTransferredProperty);
|
||||
set => SetValue(IsTransferredProperty, value);
|
||||
}
|
||||
|
||||
public static readonly DependencyProperty IsOriginProperty = DependencyProperty.Register(
|
||||
"IsOrigin", typeof(bool), typeof(TransferItem), new PropertyMetadata(ValueBoxes.TrueBox));
|
||||
|
||||
public bool IsOrigin
|
||||
{
|
||||
get => (bool)GetValue(IsOriginProperty);
|
||||
internal set => SetValue(IsOriginProperty, value);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,5 @@
|
||||
using System;
|
||||
using System.ComponentModel;
|
||||
using System.Linq;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Input;
|
||||
@@ -28,7 +27,7 @@ namespace HandyControl.Controls
|
||||
|
||||
private MessageBoxResult _messageBoxResult = MessageBoxResult.Cancel;
|
||||
|
||||
private bool _showOK;
|
||||
private bool _showOk;
|
||||
|
||||
private bool _showCancel;
|
||||
|
||||
@@ -50,7 +49,7 @@ namespace HandyControl.Controls
|
||||
{
|
||||
_messageBoxResult = MessageBoxResult.OK;
|
||||
Close();
|
||||
}, (s, e) => e.CanExecute = _showOK));
|
||||
}, (s, e) => e.CanExecute = _showOk));
|
||||
CommandBindings.Add(new CommandBinding(ControlCommands.Cancel, (s, e) =>
|
||||
{
|
||||
_messageBoxResult = MessageBoxResult.Cancel;
|
||||
@@ -92,12 +91,16 @@ namespace HandyControl.Controls
|
||||
/// <param name="caption"></param>
|
||||
public static MessageBoxResult Success(string messageBoxText, string caption = null)
|
||||
{
|
||||
var messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.OK);
|
||||
SetButtonStatus(messageBox, MessageBoxButton.OK);
|
||||
messageBox._showImage = true;
|
||||
messageBox._image = ResourceHelper.GetResource<Geometry>(ResourceToken.SuccessGeometry);
|
||||
messageBox._imageBrush = ResourceHelper.GetResource<Brush>(ResourceToken.SuccessBrush);
|
||||
messageBox.ShowDialog();
|
||||
MessageBox messageBox = null;
|
||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.OK);
|
||||
SetButtonStatus(messageBox, MessageBoxButton.OK);
|
||||
messageBox._showImage = true;
|
||||
messageBox._image = ResourceHelper.GetResource<Geometry>(ResourceToken.SuccessGeometry);
|
||||
messageBox._imageBrush = ResourceHelper.GetResource<Brush>(ResourceToken.SuccessBrush);
|
||||
messageBox.ShowDialog();
|
||||
}));
|
||||
|
||||
return messageBox._messageBoxResult;
|
||||
}
|
||||
@@ -109,10 +112,14 @@ namespace HandyControl.Controls
|
||||
/// <param name="caption"></param>
|
||||
public static MessageBoxResult Info(string messageBoxText, string caption = null)
|
||||
{
|
||||
var messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
|
||||
SetButtonStatus(messageBox, MessageBoxButton.OK);
|
||||
SetImage(messageBox, MessageBoxImage.Information);
|
||||
messageBox.ShowDialog();
|
||||
MessageBox messageBox = null;
|
||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.Information, MessageBoxResult.OK);
|
||||
SetButtonStatus(messageBox, MessageBoxButton.OK);
|
||||
SetImage(messageBox, MessageBoxImage.Information);
|
||||
messageBox.ShowDialog();
|
||||
}));
|
||||
|
||||
return messageBox._messageBoxResult;
|
||||
}
|
||||
@@ -124,10 +131,14 @@ namespace HandyControl.Controls
|
||||
/// <param name="caption"></param>
|
||||
public static MessageBoxResult Warning(string messageBoxText, string caption = null)
|
||||
{
|
||||
var messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK);
|
||||
SetButtonStatus(messageBox, MessageBoxButton.OK);
|
||||
SetImage(messageBox, MessageBoxImage.Warning);
|
||||
messageBox.ShowDialog();
|
||||
MessageBox messageBox = null;
|
||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.Warning, MessageBoxResult.OK);
|
||||
SetButtonStatus(messageBox, MessageBoxButton.OK);
|
||||
SetImage(messageBox, MessageBoxImage.Warning);
|
||||
messageBox.ShowDialog();
|
||||
}));
|
||||
|
||||
return messageBox._messageBoxResult;
|
||||
}
|
||||
@@ -139,10 +150,14 @@ namespace HandyControl.Controls
|
||||
/// <param name="caption"></param>
|
||||
public static MessageBoxResult Error(string messageBoxText, string caption = null)
|
||||
{
|
||||
var messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
|
||||
SetButtonStatus(messageBox, MessageBoxButton.OK);
|
||||
SetImage(messageBox, MessageBoxImage.Error);
|
||||
messageBox.ShowDialog();
|
||||
MessageBox messageBox = null;
|
||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.Error, MessageBoxResult.OK);
|
||||
SetButtonStatus(messageBox, MessageBoxButton.OK);
|
||||
SetImage(messageBox, MessageBoxImage.Error);
|
||||
messageBox.ShowDialog();
|
||||
}));
|
||||
|
||||
return messageBox._messageBoxResult;
|
||||
}
|
||||
@@ -154,12 +169,16 @@ namespace HandyControl.Controls
|
||||
/// <param name="caption"></param>
|
||||
public static MessageBoxResult Fatal(string messageBoxText, string caption = null)
|
||||
{
|
||||
var messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.OK);
|
||||
SetButtonStatus(messageBox, MessageBoxButton.OK);
|
||||
messageBox._showImage = true;
|
||||
messageBox._image = ResourceHelper.GetResource<Geometry>(ResourceToken.FatalGeometry);
|
||||
messageBox._imageBrush = ResourceHelper.GetResource<Brush>(ResourceToken.PrimaryTextBrush);
|
||||
messageBox.ShowDialog();
|
||||
MessageBox messageBox = null;
|
||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OK, MessageBoxImage.None, MessageBoxResult.OK);
|
||||
SetButtonStatus(messageBox, MessageBoxButton.OK);
|
||||
messageBox._showImage = true;
|
||||
messageBox._image = ResourceHelper.GetResource<Geometry>(ResourceToken.FatalGeometry);
|
||||
messageBox._imageBrush = ResourceHelper.GetResource<Brush>(ResourceToken.PrimaryTextBrush);
|
||||
messageBox.ShowDialog();
|
||||
}));
|
||||
|
||||
return messageBox._messageBoxResult;
|
||||
}
|
||||
@@ -171,36 +190,79 @@ namespace HandyControl.Controls
|
||||
/// <param name="caption"></param>
|
||||
public static MessageBoxResult Ask(string messageBoxText, string caption = null)
|
||||
{
|
||||
var messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.Cancel);
|
||||
SetButtonStatus(messageBox, MessageBoxButton.OKCancel);
|
||||
SetImage(messageBox, MessageBoxImage.Question);
|
||||
messageBox.ShowDialog();
|
||||
MessageBox messageBox = null;
|
||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
messageBox = CreateMessageBox(null, messageBoxText, caption, MessageBoxButton.OKCancel, MessageBoxImage.Question, MessageBoxResult.Cancel);
|
||||
SetButtonStatus(messageBox, MessageBoxButton.OKCancel);
|
||||
SetImage(messageBox, MessageBoxImage.Question);
|
||||
messageBox.ShowDialog();
|
||||
}));
|
||||
|
||||
return messageBox._messageBoxResult;
|
||||
}
|
||||
|
||||
public static MessageBoxResult CustomShow(string messageBoxText, string caption = null, MessageBoxButton button = MessageBoxButton.OK, string iconKey = "", string iconBrushKey = "", MessageBoxResult defaultResult = MessageBoxResult.None)
|
||||
/// <summary>
|
||||
/// 自定义信息展示
|
||||
/// </summary>
|
||||
/// <param name="info"></param>
|
||||
/// <returns></returns>
|
||||
public static MessageBoxResult Show(MessageBoxInfo info)
|
||||
{
|
||||
var messageBox = CreateMessageBox(null, messageBoxText, caption, button, MessageBoxImage.None, defaultResult);
|
||||
messageBox._showImage = true;
|
||||
messageBox._image = ResourceHelper.GetResource<Geometry>(iconKey);
|
||||
messageBox._imageBrush = ResourceHelper.GetResource<Brush>(iconBrushKey);
|
||||
messageBox.ShowDialog();
|
||||
MessageBox messageBox = null;
|
||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
messageBox = CreateMessageBox(null, info.MessageBoxText, info.Caption, info.Button, MessageBoxImage.None, info.DefaultResult);
|
||||
SetButtonStatus(messageBox, info.Button);
|
||||
|
||||
if (!string.IsNullOrEmpty(info.IconKey))
|
||||
{
|
||||
messageBox._showImage = true;
|
||||
messageBox._image = ResourceHelper.GetResource<Geometry>(info.IconKey);
|
||||
messageBox._imageBrush = ResourceHelper.GetResource<Brush>(info.IconBrushKey);
|
||||
}
|
||||
|
||||
messageBox.Style = info.Style;
|
||||
messageBox.ShowDialog();
|
||||
}));
|
||||
|
||||
return messageBox._messageBoxResult;
|
||||
}
|
||||
|
||||
public static MessageBoxResult Show(string messageBoxText, string caption = null, MessageBoxButton button = MessageBoxButton.OK, MessageBoxImage icon = MessageBoxImage.None, MessageBoxResult defaultResult = MessageBoxResult.None)
|
||||
{
|
||||
return Show(null, messageBoxText, caption, button, icon, defaultResult);
|
||||
}
|
||||
/// <summary>
|
||||
/// 信息展示
|
||||
/// </summary>
|
||||
/// <param name="messageBoxText"></param>
|
||||
/// <param name="caption"></param>
|
||||
/// <param name="button"></param>
|
||||
/// <param name="icon"></param>
|
||||
/// <param name="defaultResult"></param>
|
||||
/// <returns></returns>
|
||||
public static MessageBoxResult Show(string messageBoxText, string caption = null,
|
||||
MessageBoxButton button = MessageBoxButton.OK, MessageBoxImage icon = MessageBoxImage.None,
|
||||
MessageBoxResult defaultResult = MessageBoxResult.None) =>
|
||||
Show(null, messageBoxText, caption, button, icon, defaultResult);
|
||||
|
||||
/// <summary>
|
||||
/// 信息展示
|
||||
/// </summary>
|
||||
/// <param name="owner"></param>
|
||||
/// <param name="messageBoxText"></param>
|
||||
/// <param name="caption"></param>
|
||||
/// <param name="button"></param>
|
||||
/// <param name="icon"></param>
|
||||
/// <param name="defaultResult"></param>
|
||||
/// <returns></returns>
|
||||
public static MessageBoxResult Show(System.Windows.Window owner, string messageBoxText, string caption = null, MessageBoxButton button = MessageBoxButton.OK, MessageBoxImage icon = MessageBoxImage.None, MessageBoxResult defaultResult = MessageBoxResult.None)
|
||||
{
|
||||
var messageBox = CreateMessageBox(owner, messageBoxText, caption, button, icon, defaultResult);
|
||||
SetButtonStatus(messageBox, button);
|
||||
SetImage(messageBox, icon);
|
||||
messageBox.ShowDialog();
|
||||
MessageBox messageBox = null;
|
||||
Application.Current.Dispatcher.Invoke(new Action(() =>
|
||||
{
|
||||
messageBox = CreateMessageBox(owner, messageBoxText, caption, button, icon, defaultResult);
|
||||
SetButtonStatus(messageBox, button);
|
||||
SetImage(messageBox, icon);
|
||||
messageBox.ShowDialog();
|
||||
}));
|
||||
|
||||
return messageBox._messageBoxResult;
|
||||
}
|
||||
@@ -226,7 +288,7 @@ namespace HandyControl.Controls
|
||||
throw new InvalidEnumArgumentException(nameof(defaultResult), (int)defaultResult, typeof(MessageBoxResult));
|
||||
}
|
||||
|
||||
var ownerWindow = owner ?? Application.Current.Windows.OfType<Window>().SingleOrDefault(x => x.IsActive);
|
||||
var ownerWindow = owner ?? VisualHelper.GetActiveWindow();
|
||||
var ownerIsNull = ownerWindow is null;
|
||||
|
||||
return new MessageBox
|
||||
@@ -246,10 +308,10 @@ namespace HandyControl.Controls
|
||||
switch (messageBoxButton)
|
||||
{
|
||||
case MessageBoxButton.OK:
|
||||
messageBox._showOK = true;
|
||||
messageBox._showOk = true;
|
||||
break;
|
||||
case MessageBoxButton.OKCancel:
|
||||
messageBox._showOK = true;
|
||||
messageBox._showOk = true;
|
||||
messageBox._showCancel = true;
|
||||
break;
|
||||
case MessageBoxButton.YesNo:
|
||||
|
||||
Reference in new issue
Block a user