This commit is contained in:
liufei
2021-04-13 15:26:19 +08:00
parent cc399e2ef7
commit 5f38782623
26 changed files with 1778 additions and 1787 deletions

View File

@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Threading.Tasks;
using System.Windows;
using System.Windows;
namespace GeekDesk
{

View File

@@ -50,7 +50,7 @@ namespace DraggAnimatedPanelExample
/// <param name = "canExecuteMethod">Delegate to execute when CanExecute is called on the command. This can be null.</param>
/// <exception cref = "ArgumentNullException">When both <paramref name = "executeMethod" /> and <paramref name = "canExecuteMethod" /> ar <see langword = "null" />.</exception>
public DelegateCommand(Action<T> executeMethod, Func<T, bool> canExecuteMethod)
: base((o) => executeMethod((T) o), (o) => canExecuteMethod((T) o))
: base((o) => executeMethod((T)o), (o) => canExecuteMethod((T)o))
{
if (executeMethod == null || canExecuteMethod == null)
throw new ArgumentNullException("executeMethod");

13
Constant/AppConstant.cs Normal file
View File

@@ -0,0 +1,13 @@
using System;
namespace GeekDesk.Constant
{
class AppConstant
{
private static string APP_DIR = AppDomain.CurrentDomain.BaseDirectory.Trim();
/// <summary>
/// app数据文件路径
/// </summary>
public static string DATA_FILE_PATH = APP_DIR + "//Data"; //app数据文件路径
}
}

View File

@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
/// <summary>
/// <summary>
/// 默认参数
/// </summary>
namespace GeekDesk.Constant

View File

@@ -1,10 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GeekDesk.Constant
namespace GeekDesk.Constant
{
enum SortType
{

View File

@@ -2,183 +2,181 @@
using System;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
namespace DraggAnimatedPanel
{
/// <summary>
/// Description of SafariPanel_Drag.
/// </summary>
public partial class DraggAnimatedPanel
{
#region const drag
const double mouseDif = 2d;
const int mouseTimeDif = 25;
#endregion
/// <summary>
/// Description of SafariPanel_Drag.
/// </summary>
public partial class DraggAnimatedPanel
{
#region const drag
const double mouseDif = 2d;
const int mouseTimeDif = 25;
#endregion
#region private
UIElement __draggedElement;
#region private
UIElement __draggedElement;
public UIElement _draggedElement {
get { return __draggedElement; }
set
{
__draggedElement = value;
}
}
int _draggedIndex;
public UIElement _draggedElement
{
get { return __draggedElement; }
set
{
__draggedElement = value;
}
}
int _draggedIndex;
bool _firstScrollRequest = true;
ScrollViewer _scrollContainer;
ScrollViewer scrollViewer
{
get
{
if (_firstScrollRequest && _scrollContainer == null)
{
_firstScrollRequest = false;
_scrollContainer = (ScrollViewer)GetParent(this as DependencyObject, (ve)=>ve is ScrollViewer);
}
return _scrollContainer;
}
}
#endregion
bool _firstScrollRequest = true;
ScrollViewer _scrollContainer;
ScrollViewer scrollViewer
{
get
{
if (_firstScrollRequest && _scrollContainer == null)
{
_firstScrollRequest = false;
_scrollContainer = (ScrollViewer)GetParent(this as DependencyObject, (ve) => ve is ScrollViewer);
}
return _scrollContainer;
}
}
#endregion
#region private drag
double _lastMousePosX;
double _lastMousePosY;
int _lastMouseMoveTime;
double _x;
double _y;
Rect _rectOnDrag;
#endregion
#region private drag
double _lastMousePosX;
double _lastMousePosY;
int _lastMouseMoveTime;
double _x;
double _y;
Rect _rectOnDrag;
#endregion
void OnMouseMove(object sender,MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed && _draggedElement == null && !this.IsMouseCaptured)
StartDrag(e);
else if (_draggedElement != null)
OnDragOver(e);
}
void OnMouseMove(object sender, MouseEventArgs e)
{
if (e.LeftButton == MouseButtonState.Pressed && _draggedElement == null && !this.IsMouseCaptured)
StartDrag(e);
else if (_draggedElement != null)
OnDragOver(e);
}
void OnDragOver(MouseEventArgs e)
{
Point mousePos = Mouse.GetPosition(this);
double difX = mousePos.X - _lastMousePosX;
double difY = mousePos.Y - _lastMousePosY;
void OnDragOver(MouseEventArgs e)
{
Point mousePos = Mouse.GetPosition(this);
double difX = mousePos.X - _lastMousePosX;
double difY = mousePos.Y - _lastMousePosY;
int timeDif = e.Timestamp - _lastMouseMoveTime;
if ((Math.Abs(difX) > mouseDif || Math.Abs(difY) > mouseDif) && timeDif > mouseTimeDif)
{
//this lines is for keepn draged item inside control bounds
DoScroll();
int timeDif = e.Timestamp - _lastMouseMoveTime;
if ((Math.Abs(difX) > mouseDif || Math.Abs(difY) > mouseDif) && timeDif > mouseTimeDif)
{
//this lines is for keepn draged item inside control bounds
DoScroll();
if (_x + difX < _rectOnDrag.Location.X)
_x = 0;
else if (ItemsWidth + _x + difX > _rectOnDrag.Location.X + _rectOnDrag.Width)
_x = _rectOnDrag.Location.X + _rectOnDrag.Width - ItemsWidth;
else if (mousePos.X > _rectOnDrag.Location.X && mousePos.X < _rectOnDrag.Location.X + _rectOnDrag.Width)
_x += difX;
if (_y + difY < _rectOnDrag.Location.Y)
_y = 0;
else if (ItemsHeight + _y + difY > _rectOnDrag.Location.Y + _rectOnDrag.Height)
_y = _rectOnDrag.Location.Y + _rectOnDrag.Height - ItemsHeight;
else if (mousePos.Y > _rectOnDrag.Location.Y && mousePos.Y < _rectOnDrag.Location.Y + _rectOnDrag.Height)
_y += difY;
//lines ends
if (_x + difX < _rectOnDrag.Location.X)
_x = 0;
else if (ItemsWidth + _x + difX > _rectOnDrag.Location.X + _rectOnDrag.Width)
_x = _rectOnDrag.Location.X + _rectOnDrag.Width - ItemsWidth;
else if (mousePos.X > _rectOnDrag.Location.X && mousePos.X < _rectOnDrag.Location.X + _rectOnDrag.Width)
_x += difX;
if (_y + difY < _rectOnDrag.Location.Y)
_y = 0;
else if (ItemsHeight + _y + difY > _rectOnDrag.Location.Y + _rectOnDrag.Height)
_y = _rectOnDrag.Location.Y + _rectOnDrag.Height - ItemsHeight;
else if (mousePos.Y > _rectOnDrag.Location.Y && mousePos.Y < _rectOnDrag.Location.Y + _rectOnDrag.Height)
_y += difY;
//lines ends
AnimateTo(_draggedElement,_x,_y, 0);
_lastMousePosX = mousePos.X;
_lastMousePosY = mousePos.Y;
_lastMouseMoveTime = e.Timestamp;
SwapElement(_x + ItemsWidth/2 , _y + ItemsHeight/2);
}
}
AnimateTo(_draggedElement, _x, _y, 0);
_lastMousePosX = mousePos.X;
_lastMousePosY = mousePos.Y;
_lastMouseMoveTime = e.Timestamp;
SwapElement(_x + ItemsWidth / 2, _y + ItemsHeight / 2);
}
}
void StartDrag(MouseEventArgs e)
{
Point mousePos = Mouse.GetPosition(this);
_draggedElement = GetChildThatHasMouseOver();
if (_draggedElement == null)
return;
_draggedIndex = Children.IndexOf(_draggedElement);
_rectOnDrag = VisualTreeHelper.GetDescendantBounds(this);
Point p = GetItemVisualPoint(_draggedElement);
_x = p.X;
_y = p.Y;
SetZIndex(_draggedElement,1000);
_lastMousePosX = mousePos.X;
_lastMousePosY = mousePos.Y;
_lastMouseMoveTime = e.Timestamp;
this.InvalidateArrange();
e.Handled = true;
this.CaptureMouse();
}
void StartDrag(MouseEventArgs e)
{
Point mousePos = Mouse.GetPosition(this);
_draggedElement = GetChildThatHasMouseOver();
if (_draggedElement == null)
return;
_draggedIndex = Children.IndexOf(_draggedElement);
_rectOnDrag = VisualTreeHelper.GetDescendantBounds(this);
Point p = GetItemVisualPoint(_draggedElement);
_x = p.X;
_y = p.Y;
SetZIndex(_draggedElement, 1000);
_lastMousePosX = mousePos.X;
_lastMousePosY = mousePos.Y;
_lastMouseMoveTime = e.Timestamp;
this.InvalidateArrange();
e.Handled = true;
this.CaptureMouse();
}
void OnMouseUp(object sender,MouseEventArgs e)
{
if (this.IsMouseCaptured)
ReleaseMouseCapture();
}
void OnMouseUp(object sender, MouseEventArgs e)
{
if (this.IsMouseCaptured)
ReleaseMouseCapture();
}
void SwapElement(double x, double y)
{
int index = GetIndexFromPoint(x,y);
if (index == _draggedIndex || index < 0)
return;
if (index >= Children.Count)
index = Children.Count - 1;
void SwapElement(double x, double y)
{
int index = GetIndexFromPoint(x, y);
if (index == _draggedIndex || index < 0)
return;
if (index >= Children.Count)
index = Children.Count - 1;
int[] parameter = new int[]{_draggedIndex, index};
if (SwapCommand != null && SwapCommand.CanExecute(parameter))
{
SwapCommand.Execute(parameter);
_draggedElement = Children[index]; //this is bcause after changing the collection the element is other
FillNewDraggedChild(_draggedElement);
_draggedIndex = index;
}
int[] parameter = new int[] { _draggedIndex, index };
if (SwapCommand != null && SwapCommand.CanExecute(parameter))
{
SwapCommand.Execute(parameter);
_draggedElement = Children[index]; //this is bcause after changing the collection the element is other
FillNewDraggedChild(_draggedElement);
_draggedIndex = index;
}
this.InvalidateArrange();
}
this.InvalidateArrange();
}
void FillNewDraggedChild(UIElement child)
{
if (child.RenderTransform as TransformGroup == null)
void FillNewDraggedChild(UIElement child)
{
if (child.RenderTransform as TransformGroup == null)
{
child.RenderTransformOrigin = new Point(0.5, 0.5);
TransformGroup group = new TransformGroup();
child.RenderTransform = group;
group.Children.Add(new TranslateTransform());
}
SetZIndex(child,1000);
AnimateTo(child,_x,_y, 0); //need relocate the element
}
SetZIndex(child, 1000);
AnimateTo(child, _x, _y, 0); //need relocate the element
}
void OnLostMouseCapture(object sender,MouseEventArgs e)
{
FinishDrag();
}
void OnLostMouseCapture(object sender, MouseEventArgs e)
{
FinishDrag();
}
void FinishDrag()
{
if (_draggedElement != null)
{
SetZIndex(_draggedElement,0);
_draggedElement = null;
this.InvalidateArrange();
}
}
void FinishDrag()
{
if (_draggedElement != null)
{
SetZIndex(_draggedElement, 0);
_draggedElement = null;
this.InvalidateArrange();
}
}
void DoScroll()
void DoScroll()
{
if (scrollViewer != null)
{
Point position = Mouse.GetPosition(scrollViewer);
Point position = Mouse.GetPosition(scrollViewer);
double scrollMargin = Math.Min(scrollViewer.FontSize * 2, scrollViewer.ActualHeight / 2);
if (position.X >= scrollViewer.ActualWidth - scrollMargin &&
@@ -201,5 +199,5 @@ namespace DraggAnimatedPanel
}
}
}
}
}
}

View File

@@ -1,237 +1,234 @@
/*Developed by (doiTTeam)=>doiTTeam.mail = devdoiTTeam@gmail.com*/
using System;
using System.Linq;
using System.Runtime.CompilerServices;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Navigation;
namespace DraggAnimatedPanel
{
/// <summary>
/// Description of DraggAnimatedPanel.
/// </summary>
public partial class DraggAnimatedPanel : WrapPanel
{
#region private vars
Size _calculatedSize;
bool _isNotFirstArrange = false;
int columns, rows;
#endregion
static DraggAnimatedPanel()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(DraggAnimatedPanel), new FrameworkPropertyMetadata(typeof(DraggAnimatedPanel)));
}
/// <summary>
/// Description of DraggAnimatedPanel.
/// </summary>
public partial class DraggAnimatedPanel : WrapPanel
{
#region private vars
Size _calculatedSize;
bool _isNotFirstArrange = false;
int columns, rows;
#endregion
static DraggAnimatedPanel()
{
DefaultStyleKeyProperty.OverrideMetadata(typeof(DraggAnimatedPanel), new FrameworkPropertyMetadata(typeof(DraggAnimatedPanel)));
}
public DraggAnimatedPanel() : base()
{
this.AddHandler(Mouse.MouseMoveEvent, new MouseEventHandler(OnMouseMove), false);
this.MouseLeftButtonUp += OnMouseUp;
this.LostMouseCapture += OnLostMouseCapture;
}
public DraggAnimatedPanel() : base()
{
this.AddHandler(Mouse.MouseMoveEvent, new MouseEventHandler(OnMouseMove), false);
this.MouseLeftButtonUp += OnMouseUp;
this.LostMouseCapture += OnLostMouseCapture;
}
UIElement GetChildThatHasMouseOver()
{
return GetParent(Mouse.DirectlyOver as DependencyObject, (ve) => Children.Contains(ve as UIElement)) as UIElement;
}
UIElement GetChildThatHasMouseOver()
{
return GetParent(Mouse.DirectlyOver as DependencyObject, (ve) => Children.Contains(ve as UIElement)) as UIElement;
}
Point GetItemVisualPoint(UIElement element)
{
TransformGroup group = (TransformGroup)element.RenderTransform;
TranslateTransform trans = (TranslateTransform)group.Children[0];
Point GetItemVisualPoint(UIElement element)
{
TransformGroup group = (TransformGroup)element.RenderTransform;
TranslateTransform trans = (TranslateTransform)group.Children[0];
return new Point(trans.X, trans.Y);
}
return new Point(trans.X, trans.Y);
}
int GetIndexFromPoint(double x, double y)
{
int columnIndex = (int)Math.Truncate(x / itemContainterWidth);
int rowIndex = (int)Math.Truncate(y / itemContainterHeight);
return columns * rowIndex + columnIndex;
}
int GetIndexFromPoint(Point p)
{
return GetIndexFromPoint(p.X, p.Y);
}
int GetIndexFromPoint(double x, double y)
{
int columnIndex = (int)Math.Truncate(x / itemContainterWidth);
int rowIndex = (int)Math.Truncate(y / itemContainterHeight);
return columns * rowIndex + columnIndex;
}
int GetIndexFromPoint(Point p)
{
return GetIndexFromPoint(p.X, p.Y);
}
#region dependency properties
public static readonly DependencyProperty ItemsWidthProperty =
DependencyProperty.Register(
"ItemsWidth",
typeof(double),
typeof(DraggAnimatedPanel),
new FrameworkPropertyMetadata(150d));
#region dependency properties
public static readonly DependencyProperty ItemsWidthProperty =
DependencyProperty.Register(
"ItemsWidth",
typeof(double),
typeof(DraggAnimatedPanel),
new FrameworkPropertyMetadata(150d));
public static readonly DependencyProperty ItemsHeightProperty =
DependencyProperty.Register(
"ItemsHeight",
typeof(double),
typeof(DraggAnimatedPanel),
new FrameworkPropertyMetadata(60d));
public static readonly DependencyProperty ItemsHeightProperty =
DependencyProperty.Register(
"ItemsHeight",
typeof(double),
typeof(DraggAnimatedPanel),
new FrameworkPropertyMetadata(60d));
public static readonly DependencyProperty ItemSeparationProperty =
DependencyProperty.Register(
"ItemSeparation",
typeof(Thickness),
typeof(DraggAnimatedPanel),
new FrameworkPropertyMetadata());
public static readonly DependencyProperty ItemSeparationProperty =
DependencyProperty.Register(
"ItemSeparation",
typeof(Thickness),
typeof(DraggAnimatedPanel),
new FrameworkPropertyMetadata());
// Using a DependencyProperty as the backing store for AnimationMilliseconds. This enables animation, styling, binding, etc...
public static readonly DependencyProperty AnimationMillisecondsProperty =
DependencyProperty.Register("AnimationMilliseconds", typeof(int), typeof(DraggAnimatedPanel), new FrameworkPropertyMetadata(200));
// Using a DependencyProperty as the backing store for AnimationMilliseconds. This enables animation, styling, binding, etc...
public static readonly DependencyProperty AnimationMillisecondsProperty =
DependencyProperty.Register("AnimationMilliseconds", typeof(int), typeof(DraggAnimatedPanel), new FrameworkPropertyMetadata(200));
public static readonly DependencyProperty SwapCommandProperty =
DependencyProperty.Register(
"SwapCommand",
typeof(ICommand),
typeof(DraggAnimatedPanel),
new FrameworkPropertyMetadata(null));
public static readonly DependencyProperty SwapCommandProperty =
DependencyProperty.Register(
"SwapCommand",
typeof(ICommand),
typeof(DraggAnimatedPanel),
new FrameworkPropertyMetadata(null));
#endregion
#endregion
#region properties
public double ItemsWidth
{
get { return (double)GetValue(ItemsWidthProperty); }
set { SetValue(ItemsWidthProperty, value); }
}
public double ItemsHeight
{
get { return (double)GetValue(ItemsHeightProperty); }
set { SetValue(ItemsHeightProperty, value); }
}
public Thickness ItemSeparation
{
get { return (Thickness)this.GetValue(ItemSeparationProperty); }
set { this.SetValue(ItemSeparationProperty, value); }
}
public int AnimationMilliseconds
{
get { return (int)GetValue(AnimationMillisecondsProperty); }
set { SetValue(AnimationMillisecondsProperty, value); }
}
private double itemContainterHeight
{
get { return ItemSeparation.Top + ItemsHeight + ItemSeparation.Bottom; }
}
private double itemContainterWidth
{
get { return ItemSeparation.Left + ItemsWidth + ItemSeparation.Right; }
}
public ICommand SwapCommand
{
get { return (ICommand)GetValue(SwapCommandProperty); }
set { SetValue(SwapCommandProperty, value); }
}
#endregion
#region properties
public double ItemsWidth
{
get { return (double)GetValue(ItemsWidthProperty); }
set { SetValue(ItemsWidthProperty, value); }
}
public double ItemsHeight
{
get { return (double)GetValue(ItemsHeightProperty); }
set { SetValue(ItemsHeightProperty, value); }
}
public Thickness ItemSeparation
{
get { return (Thickness)this.GetValue(ItemSeparationProperty); }
set { this.SetValue(ItemSeparationProperty, value); }
}
public int AnimationMilliseconds
{
get { return (int)GetValue(AnimationMillisecondsProperty); }
set { SetValue(AnimationMillisecondsProperty, value); }
}
private double itemContainterHeight
{
get { return ItemSeparation.Top + ItemsHeight + ItemSeparation.Bottom; }
}
private double itemContainterWidth
{
get { return ItemSeparation.Left + ItemsWidth + ItemSeparation.Right; }
}
public ICommand SwapCommand
{
get { return (ICommand)GetValue(SwapCommandProperty); }
set { SetValue(SwapCommandProperty, value); }
}
#endregion
#region transformation things
private void AnimateAll()
{
//Apply exactly the same algorithm, but instide of Arrange a call AnimateTo method
double colPosition = 0;
double rowPosition = 0;
foreach (UIElement child in Children)
{
if (child != _draggedElement)
AnimateTo(child, colPosition + ItemSeparation.Left, rowPosition + ItemSeparation.Top, _isNotFirstArrange ? AnimationMilliseconds : 0);
//drag will locate dragged element
colPosition += itemContainterWidth;
if (colPosition + 1 > _calculatedSize.Width)
{
colPosition = 0;
rowPosition += itemContainterHeight;
}
}
}
#region transformation things
private void AnimateAll()
{
//Apply exactly the same algorithm, but instide of Arrange a call AnimateTo method
double colPosition = 0;
double rowPosition = 0;
foreach (UIElement child in Children)
{
if (child != _draggedElement)
AnimateTo(child, colPosition + ItemSeparation.Left, rowPosition + ItemSeparation.Top, _isNotFirstArrange ? AnimationMilliseconds : 0);
//drag will locate dragged element
colPosition += itemContainterWidth;
if (colPosition + 1 > _calculatedSize.Width)
{
colPosition = 0;
rowPosition += itemContainterHeight;
}
}
}
private void AnimateTo(UIElement child, double x, double y, int duration)
{
TransformGroup group = (TransformGroup)child.RenderTransform;
TranslateTransform trans = (TranslateTransform)group.Children.First((groupElement) => groupElement is TranslateTransform);
private void AnimateTo(UIElement child, double x, double y, int duration)
{
TransformGroup group = (TransformGroup)child.RenderTransform;
TranslateTransform trans = (TranslateTransform)group.Children.First((groupElement) => groupElement is TranslateTransform);
trans.BeginAnimation(TranslateTransform.XProperty, MakeAnimation(x, duration));
trans.BeginAnimation(TranslateTransform.YProperty, MakeAnimation(y, duration));
}
trans.BeginAnimation(TranslateTransform.XProperty, MakeAnimation(x, duration));
trans.BeginAnimation(TranslateTransform.YProperty, MakeAnimation(y, duration));
}
private DoubleAnimation MakeAnimation(double to, int duration)
{
DoubleAnimation anim = new DoubleAnimation(to, TimeSpan.FromMilliseconds(duration));
anim.AccelerationRatio = 0.2;
anim.DecelerationRatio = 0.7;
return anim;
}
#endregion
private DoubleAnimation MakeAnimation(double to, int duration)
{
DoubleAnimation anim = new DoubleAnimation(to, TimeSpan.FromMilliseconds(duration));
anim.AccelerationRatio = 0.2;
anim.DecelerationRatio = 0.7;
return anim;
}
#endregion
#region measure
protected override Size MeasureOverride(Size availableSize)
{
Size itemContainerSize = new Size(itemContainterWidth, itemContainterHeight);
int count = 0; //for not call it again
foreach (UIElement child in Children)
{
child.Measure(itemContainerSize);
count++;
}
if (availableSize.Width < itemContainterWidth)
_calculatedSize = new Size(itemContainterWidth, count * itemContainterHeight); //the size of nX1
else
{
columns = (int)Math.Truncate(availableSize.Width / itemContainterWidth);
rows = count / columns;
if (count % columns != 0)
rows++;
_calculatedSize = new Size(columns * itemContainterWidth, rows * itemContainterHeight);
}
return _calculatedSize;
}
#endregion
#region measure
protected override Size MeasureOverride(Size availableSize)
{
Size itemContainerSize = new Size(itemContainterWidth, itemContainterHeight);
int count = 0; //for not call it again
foreach (UIElement child in Children)
{
child.Measure(itemContainerSize);
count++;
}
if (availableSize.Width < itemContainterWidth)
_calculatedSize = new Size(itemContainterWidth, count * itemContainterHeight); //the size of nX1
else
{
columns = (int)Math.Truncate(availableSize.Width / itemContainterWidth);
rows = count / columns;
if (count % columns != 0)
rows++;
_calculatedSize = new Size(columns * itemContainterWidth, rows * itemContainterHeight);
}
return _calculatedSize;
}
#endregion
#region arrange
protected override Size ArrangeOverride(Size finalSize)
{
Size _finalItemSize = new Size(ItemsWidth, ItemsHeight);
//if is animated then arrange elements to 0,0, and then put them on its location using the transform
foreach (UIElement child in InternalChildren)
{
// If this is the first time we've seen this child, add our transforms
if (child.RenderTransform as TransformGroup == null)
{
child.RenderTransformOrigin = new Point(0.5, 0.5);
TransformGroup group = new TransformGroup();
child.RenderTransform = group;
group.Children.Add(new TranslateTransform());
}
//locate all children in 0,0 point//TODO: use infinity and then scale each element to items size
child.Arrange(new Rect(new Point(0, 0), _finalItemSize)); //when use transformations change to childs.DesireSize
}
AnimateAll();
#region arrange
protected override Size ArrangeOverride(Size finalSize)
{
Size _finalItemSize = new Size(ItemsWidth, ItemsHeight);
//if is animated then arrange elements to 0,0, and then put them on its location using the transform
foreach (UIElement child in InternalChildren)
{
// If this is the first time we've seen this child, add our transforms
if (child.RenderTransform as TransformGroup == null)
{
child.RenderTransformOrigin = new Point(0.5, 0.5);
TransformGroup group = new TransformGroup();
child.RenderTransform = group;
group.Children.Add(new TranslateTransform());
}
//locate all children in 0,0 point//TODO: use infinity and then scale each element to items size
child.Arrange(new Rect(new Point(0, 0), _finalItemSize)); //when use transformations change to childs.DesireSize
}
AnimateAll();
if (!_isNotFirstArrange)
_isNotFirstArrange = true;
if (!_isNotFirstArrange)
_isNotFirstArrange = true;
return _calculatedSize;
}
#endregion
return _calculatedSize;
}
#endregion
#region Static
//this can be an extension method
public static DependencyObject GetParent(DependencyObject o, Func<DependencyObject, bool> matchFunction)
{
DependencyObject t = o;
do
{
t = VisualTreeHelper.GetParent(t);
} while (t != null && !matchFunction.Invoke(t));
return t;
}
#endregion
#region Static
//this can be an extension method
public static DependencyObject GetParent(DependencyObject o, Func<DependencyObject, bool> matchFunction)
{
DependencyObject t = o;
do
{
t = VisualTreeHelper.GetParent(t);
} while (t != null && !matchFunction.Invoke(t));
return t;
}
#endregion
//TODO: Add IsEditing property
//TODO: Add Scale transform to items for fill items area
}
//TODO: Add IsEditing property
//TODO: Add Scale transform to items for fill items area
}
}

View File

@@ -85,6 +85,7 @@
</ApplicationDefinition>
<Compile Include="Command\DelegateCommand.cs" />
<Compile Include="Command\DelegateCommandBase.cs" />
<Compile Include="Constant\AppConstant.cs" />
<Compile Include="Constant\DefaultConstant.cs" />
<Compile Include="Constant\SortType.cs" />
<Compile Include="DraggAnimatedPanel\DraggAnimatedPanel.cs" />
@@ -98,9 +99,8 @@
<Compile Include="Util\MouseUtilities.cs" />
<Compile Include="Util\SystemIcon.cs" />
<Compile Include="ViewModel\AppConfig.cs" />
<Compile Include="ViewModel\DataInfos.cs" />
<Compile Include="ViewModel\MainModel.cs" />
<Compile Include="ViewModel\MainViewModel.cs" />
<Compile Include="ViewModel\AppData.cs" />
<Compile Include="ViewModel\IconInfo.cs" />
<Compile Include="ViewModel\MenuViewModel.cs" />
<Page Include="MainWindow.xaml">
<Generator>MSBuild:Compile</Generator>

View File

@@ -8,7 +8,7 @@
xmlns:util="clr-namespace:GeekDesk.Util"
xmlns:DraggAnimatedPanel="clr-namespace:DraggAnimatedPanel" x:Name="window"
xmlns:hc="https://handyorg.github.io/handycontrol"
Title="MainWindow" Height="450" Width="800">
Title="MainWindow" Height="500" Width="600">
<Window.Resources>
<Style x:Key="ListBoxStyle" BasedOn="{StaticResource ListBoxBaseStyle}" TargetType="ListBox"/>
@@ -143,7 +143,7 @@
</ListBox.ItemTemplate>
</ListBox>-->
<ListBox x:Name="menu" ItemsSource="{Binding}">
<ListBox x:Name="menus" ItemsSource="{Binding MenuList}">
<ListBox.Resources>
<ContextMenu x:Key="menuDialog" Width="200">
<MenuItem Header="新建菜单"/>
@@ -165,7 +165,7 @@
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding menu}" PreviewMouseLeftButtonDown="menuClick" />
<TextBlock Text="{Binding}" PreviewMouseLeftButtonDown="menuClick" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
@@ -176,31 +176,29 @@
<!--右侧栏-->
<hc:Card AllowDrop="True" Drop="Wrap_Drop" Opacity="1" x:Name="rightCard" Grid.Row="1" Grid.Column="1" BorderThickness="1" Effect="{DynamicResource EffectShadow2}" Margin="5,5,5,5">
<WrapPanel Orientation="Horizontal">
<ListBox x:Name="data" ItemsSource="{Binding}"
<ListBox x:Name="icons" ItemsSource="{Binding}"
BorderThickness="0"
SelectionChanged="data_SelectionChanged"
>
<!--<ListBox.ItemContainerStyle>
<Style TargetType="{x:Type ListBoxItem}" BasedOn="{StaticResource dataStyle}"/>
</ListBox.ItemContainerStyle>-->
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<DraggAnimatedPanel:DraggAnimatedPanel ItemsHeight="115" ItemsWidth="100" HorizontalAlignment="Center" SwapCommand="{Binding SwapCommand, RelativeSource={RelativeSource AncestorType={x:Type Window}}}"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemTemplate>
<DataTemplate>
<Border Margin="5,5,5,5" CornerRadius="10">
<StackPanel Tag="{Binding Path}"
<StackPanel Tag="{Binding}"
MouseLeftButtonDown="dataClick"
HorizontalAlignment="Center"
hc:Poptip.HitMode="None"
hc:Poptip.IsOpen="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}"
hc:Poptip.Content="{Binding Path}"
hc:Poptip.Placement="BottomLeft"
Margin="5,5,5,5"
Height="115"
hc:Poptip.HitMode="None"
hc:Poptip.IsOpen="{Binding IsMouseOver, RelativeSource={RelativeSource Self}}"
hc:Poptip.Content="{Binding Content}"
hc:Poptip.Placement="BottomLeft"
>
<Image Style="{StaticResource imageStyle}"></Image>
<TextBlock Width="80" TextWrapping="Wrap" TextAlignment="Center" Height="35" LineHeight="15" FontSize="12" Text="{Binding Name}"/>

View File

@@ -1,22 +1,15 @@
using System;
using DraggAnimatedPanelExample;
using GalaSoft.MvvmLight;
using GeekDesk.Util;
using GeekDesk.ViewModel;
using System;
using System.Collections.Generic;
using System.IO;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Input;
using System.Windows.Media.Imaging;
using GeekDesk.ViewModel;
using System.IO;
using GeekDesk.Util;
using GalaSoft.MvvmLight;
using System.Windows.Controls;
using System.Windows.Media;
using System.Collections.ObjectModel;
using WPF.JoshSmith.ServiceProviders.UI;
using DraggAnimatedPanelExample;
using System.ComponentModel;
namespace GeekDesk
{
/// <summary>
@@ -25,15 +18,18 @@ namespace GeekDesk
///
public partial class MainWindow : Window
{
private static MainModel mainModel;
ListViewDragDropManager<ViewModel.Menu> dragMgr;
ListViewDragDropManager<ViewModel.DataInfos> dragMgr2;
private static AppData appData = CommonCode.GetAppData();
public MainWindow()
{
InitializeComponent();
loadData();
List<string> menuList = new List<string>();
Dictionary<string, List<IconInfo>> iconMap = new Dictionary<string, List<IconInfo>>();
mainModel = new MainModel();
//this.DataContext = mainModel;
//menu.Items = mainModel;
//System.Diagnostics.Process.Start(@"D:\SoftWare\WeGame\wegame.exe");
@@ -41,6 +37,29 @@ namespace GeekDesk
this.SizeChanged += MainWindow_Resize;
}
private void loadData()
{
this.DataContext = appData;
appData.MenuList.Add("Test1");
this.Width = appData.AppConfig.WindowWidth;
this.Height = appData.AppConfig.WindowHeight;
List<IconInfo> iconList;
if (appData.IconMap.ContainsKey("1"))
{
iconList = appData.IconMap["1"];
}
else
{
iconList = new List<IconInfo>();
appData.IconMap.Add("1", iconList);
}
icons.ItemsSource = iconList;
}
DelegateCommand<int[]> _swap;
public DelegateCommand<int[]> SwapCommand
{
@@ -52,17 +71,17 @@ namespace GeekDesk
{
int fromS = indexes[0];
int to = indexes[1];
var elementSource = data.Items[to];
var dragged = data.Items[fromS];
var elementSource = icons.Items[to];
var dragged = icons.Items[fromS];
if (fromS > to)
{
data.Items.Remove(dragged);
data.Items.Insert(to, dragged);
icons.Items.Remove(dragged);
icons.Items.Insert(to, dragged);
}
else
{
data.Items.Remove(dragged);
data.Items.Insert(to, dragged);
icons.Items.Remove(dragged);
icons.Items.Insert(to, dragged);
}
}
);
@@ -80,17 +99,17 @@ namespace GeekDesk
{
int fromS = indexes[0];
int to = indexes[1];
var elementSource = menu.Items[to];
var dragged = menu.Items[fromS];
var elementSource = menus.Items[to];
var dragged = menus.Items[fromS];
if (fromS > to)
{
menu.Items.Remove(dragged);
menu.Items.Insert(to, dragged);
menus.Items.Remove(dragged);
menus.Items.Insert(to, dragged);
}
else
{
menu.Items.Remove(dragged);
menu.Items.Insert(to, dragged);
menus.Items.Remove(dragged);
menus.Items.Insert(to, dragged);
}
}
);
@@ -104,23 +123,41 @@ namespace GeekDesk
{
Array dropObject = (System.Array)e.Data.GetData(DataFormats.FileDrop);
if (dropObject == null) return;
string path = (string)dropObject.GetValue(0);
if (File.Exists(path))
foreach (object obj in dropObject)
{
// 文件
BitmapImage bi = FileIcon.GetBitmapImage(path);
DataInfos infos = new DataInfos();
infos.Path = path;
infos.BitmapImage = bi;
infos.Name = Path.GetFileNameWithoutExtension(path);
data.Items.Add(infos);
data.Items.Refresh();
}
else if (Directory.Exists(path))
{
//文件夹
string path = (string)obj;
if (File.Exists(path))
{
// 文件
BitmapImage bi = FileIcon.GetBitmapImage(path);
IconInfo iconInfo = new IconInfo();
iconInfo.Path = path;
iconInfo.BitmapImage = bi;
iconInfo.Name = Path.GetFileNameWithoutExtension(path);
List<IconInfo> iconList;
if (appData.IconMap.ContainsKey("1"))
{
iconList = appData.IconMap["1"];
}
else
{
iconList = new List<IconInfo>();
appData.IconMap.Add("1", iconList);
}
iconList.Add(iconInfo);
icons.ItemsSource = iconList;
CommonCode.SaveAppData(appData);
}
else if (Directory.Exists(path))
{
//文件夹
}
}
icons.Items.Refresh();
}
@@ -139,8 +176,10 @@ namespace GeekDesk
/// <param name="e"></param>
private void dataClick(object sender, MouseButtonEventArgs e)
{
//string path = ((StackPanel)sender).Tag.ToString();
//System.Diagnostics.Process.Start(path);
IconInfo icon = (IconInfo)((StackPanel)sender).Tag;
System.Diagnostics.Process.Start(icon.Path);
icon.Count++;
CommonCode.SaveAppData(appData);
}
/// <summary>
@@ -150,128 +189,42 @@ namespace GeekDesk
/// <param name="e"></param>
private void data_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
if (data.SelectedIndex != -1) data.SelectedIndex = -1;
if (icons.SelectedIndex != -1) icons.SelectedIndex = -1;
}
#region Window_Loaded
void Window_Loaded(object sender, RoutedEventArgs e)
{
AppConfig config = CommonCode.GetAppConfig();
this.Width = config.WindowWidth;
this.Height = config.WindowHeight;
this.DataContext = config;
this.menu.Items.Add(new ViewModel.Menu() { menu = "test1" });
this.menu.Items.Add(new ViewModel.Menu() { menu = "test2" });
this.menu.Items.Add(new ViewModel.Menu() { menu = "test3" });
//this.menus.Items.Add(new ViewModel.Menu() { menu = "test1" });
//this.menus.Items.Add(new ViewModel.Menu() { menu = "test2" });
//this.menus.Items.Add(new ViewModel.Menu() { menu = "test3" });
}
#endregion // Window_Loaded
#region Window_Closing
void Window_Closing(object sender, CancelEventArgs e)
{
Rect rect = this.RestoreBounds;
AppConfig config = this.DataContext as AppConfig;
config.WindowWidth = rect.Width;
config.WindowHeight = rect.Height;
CommonCode.SaveAppConfig(config);
}
#endregion // Window_Closing
//#region Window_Closing
//void Window_Closing(object sender, CancelEventArgs e)
//{
// Rect rect = this.RestoreBounds;
// AppConfig config = this.DataContext as AppConfig;
// config.WindowWidth = rect.Width;
// config.WindowHeight = rect.Height;
// CommonCode.SaveAppConfig(config);
//}
//#endregion // Window_Closing
void MainWindow_Resize(object sender, System.EventArgs e)
{
if (this.DataContext != null)
{
AppConfig config = this.DataContext as AppConfig;
config.WindowWidth = this.Width;
config.WindowHeight = this.Height;
CommonCode.SaveAppConfig(config);
}
}
#region dragMgr_ProcessDrop
// Performs custom drop logic for the top ListView.
void dragMgr_ProcessDrop(object sender, ProcessDropEventArgs<object> e)
{
// This shows how to customize the behavior of a drop.
// Here we perform a swap, instead of just moving the dropped item.
int higherIdx = Math.Max(e.OldIndex, e.NewIndex);
int lowerIdx = Math.Min(e.OldIndex, e.NewIndex);
if (lowerIdx < 0)
{
// The item came from the lower ListView
// so just insert it.
e.ItemsSource.Insert(higherIdx, e.DataItem);
}
else
{
// null values will cause an error when calling Move.
// It looks like a bug in ObservableCollection to me.
if (e.ItemsSource[lowerIdx] == null ||
e.ItemsSource[higherIdx] == null)
return;
// The item came from the ListView into which
// it was dropped, so swap it with the item
// at the target index.
e.ItemsSource.Move(lowerIdx, higherIdx);
e.ItemsSource.Move(higherIdx - 1, lowerIdx);
}
// Set this to 'Move' so that the OnListViewDrop knows to
// remove the item from the other ListView.
e.Effects = DragDropEffects.Move;
}
#endregion // dragMgr_ProcessDrop
#region OnListViewDragEnter
// Handles the DragEnter event for both ListViews.
void OnListViewDragEnter(object sender, DragEventArgs e)
{
e.Effects = DragDropEffects.Move;
}
#endregion // OnListViewDragEnter
#region OnListViewDrop
// Handles the Drop event for both ListViews.
void OnListViewDrop(object sender, DragEventArgs e)
{
if (e.Effects == DragDropEffects.None)
return;
ViewModel.Menu menuV = e.Data.GetData(typeof(ViewModel.Menu)) as ViewModel.Menu;
DataInfos data = e.Data.GetData(typeof(DataInfos)) as DataInfos;
if (sender == this.menu)
{
if (this.dragMgr.IsDragInProgress)
return;
// An item was dragged from the bottom ListView into the top ListView
// so remove that item from the bottom ListView.
(this.data.ItemsSource as ObservableCollection<DataInfos>).Remove(data);
}
else
{
if (this.dragMgr2.IsDragInProgress)
return;
// An item was dragged from the top ListView into the bottom ListView
// so remove that item from the top ListView.
(this.menu.ItemsSource as ObservableCollection<ViewModel.Menu>).Remove(menuV);
AppData appData = this.DataContext as AppData;
appData.AppConfig.WindowWidth = this.Width;
appData.AppConfig.WindowHeight = this.Height;
CommonCode.SaveAppData(appData);
}
}
#endregion // OnListViewDrop
private void leftCard_MouseRightButtonDown(object sender, MouseButtonEventArgs e)
{
@@ -287,13 +240,13 @@ namespace GeekDesk
ViewModel.Menu pojo = (ViewModel.Menu)((ContextMenu)((MenuItem)sender).Parent).DataContext;
string menuTitle = pojo.menu;
int index = 0;
foreach (object obj in menu.Items)
foreach (object obj in menus.Items)
{
string test = ((ViewModel.Menu)obj).menu;
if (test == menuTitle)
{
menu.Items.RemoveAt(index);
menu.Items.Refresh();
menus.Items.RemoveAt(index);
menus.Items.Refresh();
return;
}
index++;
@@ -301,10 +254,7 @@ namespace GeekDesk
}
public Double ConvertString(string val)
{
return Convert.ToDouble(val);
}
}
@@ -315,7 +265,7 @@ namespace GeekDesk
{
public List<ViewModel.Menu> MenuList { get; set; }
public List<ViewModel.DataInfos> DataList { get; set; }
public List<ViewModel.IconInfo> DataList { get; set; }
}

View File

@@ -1,6 +1,4 @@
using System.Reflection;
using System.Resources;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
using System.Windows;

View File

@@ -1,12 +1,7 @@
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.Serialization.Formatters.Binary;
using System.Text;
using System.Threading.Tasks;
using GeekDesk.Constant;
using GeekDesk.ViewModel;
using System.IO;
using System.Runtime.Serialization.Formatters.Binary;
/// <summary>
/// 提取一些代码
@@ -15,45 +10,49 @@ namespace GeekDesk.Util
{
class CommonCode
{
private static string appConfigFilePath = AppDomain.CurrentDomain.BaseDirectory.Trim() + "\\config";
/// <summary>
/// 获取app配置
/// 获取app 数据
/// </summary>
/// <returns></returns>
public static AppConfig GetAppConfig()
public static AppData GetAppData()
{
AppConfig config;
if (!File.Exists(appConfigFilePath))
AppData appData;
if (!File.Exists(AppConstant.DATA_FILE_PATH))
{
using (FileStream fs = File.Create(appConfigFilePath)) { }
config = new AppConfig();
SaveAppConfig(config);
using (FileStream fs = File.Create(AppConstant.DATA_FILE_PATH)) { }
appData = new AppData();
SaveAppData(appData);
}
else
{
using (FileStream fs = new FileStream(appConfigFilePath, FileMode.Open))
using (FileStream fs = new FileStream(AppConstant.DATA_FILE_PATH, FileMode.Open))
{
BinaryFormatter bf = new BinaryFormatter();
string json = bf.Deserialize(fs) as string;
config = JsonConvert.DeserializeObject<AppConfig>(json);
appData = bf.Deserialize(fs) as AppData;
}
}
return config;
return appData;
}
/// <summary>
/// 保存app配置
/// 保存app 数据
/// </summary>
/// <param name="config"></param>
public static void SaveAppConfig(AppConfig config)
/// <param name="appData"></param>
public static void SaveAppData(AppData appData)
{
using (FileStream fs = new FileStream(appConfigFilePath, FileMode.Create))
using (FileStream fs = new FileStream(AppConstant.DATA_FILE_PATH, FileMode.Create))
{
BinaryFormatter bf = new BinaryFormatter();
string json = JsonConvert.SerializeObject(config);
bf.Serialize(fs, json);
bf.Serialize(fs, appData);
}
}
}
}

View File

@@ -1,12 +1,8 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices;
using System.Security;
using System.Text;
using System.Threading.Tasks;
namespace GeekDesk.Util
{

View File

@@ -1,175 +1,170 @@
// Copyright (C) Josh Smith - January 2007
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows.Documents;
using System.Windows;
using System.Windows.Documents;
using System.Windows.Media;
using System.Windows.Shapes;
using System.Windows.Media.Animation;
using System.Windows.Controls;
namespace WPF.JoshSmith.Adorners
{
/// <summary>
/// Renders a visual which can follow the mouse cursor,
/// such as during a drag-and-drop operation.
/// </summary>
public class DragAdorner : Adorner
{
#region Data
/// <summary>
/// Renders a visual which can follow the mouse cursor,
/// such as during a drag-and-drop operation.
/// </summary>
public class DragAdorner : Adorner
{
#region Data
private Rectangle child = null;
private double offsetLeft = 0;
private double offsetTop = 0;
private Rectangle child = null;
private double offsetLeft = 0;
private double offsetTop = 0;
#endregion // Data
#endregion // Data
#region Constructor
#region Constructor
/// <summary>
/// Initializes a new instance of DragVisualAdorner.
/// </summary>
/// <param name="adornedElement">The element being adorned.</param>
/// <param name="size">The size of the adorner.</param>
/// <param name="brush">A brush to with which to paint the adorner.</param>
public DragAdorner( UIElement adornedElement, Size size, Brush brush )
: base( adornedElement )
{
Rectangle rect = new Rectangle();
rect.Fill = brush;
rect.Width = size.Width;
rect.Height = size.Height;
rect.IsHitTestVisible = false;
this.child = rect;
}
/// <summary>
/// Initializes a new instance of DragVisualAdorner.
/// </summary>
/// <param name="adornedElement">The element being adorned.</param>
/// <param name="size">The size of the adorner.</param>
/// <param name="brush">A brush to with which to paint the adorner.</param>
public DragAdorner(UIElement adornedElement, Size size, Brush brush)
: base(adornedElement)
{
Rectangle rect = new Rectangle();
rect.Fill = brush;
rect.Width = size.Width;
rect.Height = size.Height;
rect.IsHitTestVisible = false;
this.child = rect;
}
#endregion // Constructor
#endregion // Constructor
#region Public Interface
#region Public Interface
#region GetDesiredTransform
#region GetDesiredTransform
/// <summary>
/// Override.
/// </summary>
/// <param name="transform"></param>
/// <returns></returns>
public override GeneralTransform GetDesiredTransform( GeneralTransform transform )
{
GeneralTransformGroup result = new GeneralTransformGroup();
result.Children.Add( base.GetDesiredTransform( transform ) );
result.Children.Add( new TranslateTransform( this.offsetLeft, this.offsetTop ) );
return result;
}
/// <summary>
/// Override.
/// </summary>
/// <param name="transform"></param>
/// <returns></returns>
public override GeneralTransform GetDesiredTransform(GeneralTransform transform)
{
GeneralTransformGroup result = new GeneralTransformGroup();
result.Children.Add(base.GetDesiredTransform(transform));
result.Children.Add(new TranslateTransform(this.offsetLeft, this.offsetTop));
return result;
}
#endregion // GetDesiredTransform
#endregion // GetDesiredTransform
#region OffsetLeft
#region OffsetLeft
/// <summary>
/// Gets/sets the horizontal offset of the adorner.
/// </summary>
public double OffsetLeft
{
get { return this.offsetLeft; }
set
{
this.offsetLeft = value;
UpdateLocation();
}
}
/// <summary>
/// Gets/sets the horizontal offset of the adorner.
/// </summary>
public double OffsetLeft
{
get { return this.offsetLeft; }
set
{
this.offsetLeft = value;
UpdateLocation();
}
}
#endregion // OffsetLeft
#endregion // OffsetLeft
#region SetOffsets
#region SetOffsets
/// <summary>
/// Updates the location of the adorner in one atomic operation.
/// </summary>
/// <param name="left"></param>
/// <param name="top"></param>
public void SetOffsets( double left, double top )
{
this.offsetLeft = left;
this.offsetTop = top;
this.UpdateLocation();
}
/// <summary>
/// Updates the location of the adorner in one atomic operation.
/// </summary>
/// <param name="left"></param>
/// <param name="top"></param>
public void SetOffsets(double left, double top)
{
this.offsetLeft = left;
this.offsetTop = top;
this.UpdateLocation();
}
#endregion // SetOffsets
#endregion // SetOffsets
#region OffsetTop
#region OffsetTop
/// <summary>
/// Gets/sets the vertical offset of the adorner.
/// </summary>
public double OffsetTop
{
get { return this.offsetTop; }
set
{
this.offsetTop = value;
UpdateLocation();
}
}
/// <summary>
/// Gets/sets the vertical offset of the adorner.
/// </summary>
public double OffsetTop
{
get { return this.offsetTop; }
set
{
this.offsetTop = value;
UpdateLocation();
}
}
#endregion // OffsetTop
#endregion // OffsetTop
#endregion // Public Interface
#endregion // Public Interface
#region Protected Overrides
#region Protected Overrides
/// <summary>
/// Override.
/// </summary>
/// <param name="constraint"></param>
/// <returns></returns>
protected override Size MeasureOverride( Size constraint )
{
this.child.Measure( constraint );
return this.child.DesiredSize;
}
/// <summary>
/// Override.
/// </summary>
/// <param name="constraint"></param>
/// <returns></returns>
protected override Size MeasureOverride(Size constraint)
{
this.child.Measure(constraint);
return this.child.DesiredSize;
}
/// <summary>
/// Override.
/// </summary>
/// <param name="finalSize"></param>
/// <returns></returns>
protected override Size ArrangeOverride( Size finalSize )
{
this.child.Arrange( new Rect( finalSize ) );
return finalSize;
}
/// <summary>
/// Override.
/// </summary>
/// <param name="finalSize"></param>
/// <returns></returns>
protected override Size ArrangeOverride(Size finalSize)
{
this.child.Arrange(new Rect(finalSize));
return finalSize;
}
/// <summary>
/// Override.
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
protected override Visual GetVisualChild( int index )
{
return this.child;
}
/// <summary>
/// Override.
/// </summary>
/// <param name="index"></param>
/// <returns></returns>
protected override Visual GetVisualChild(int index)
{
return this.child;
}
/// <summary>
/// Override. Always returns 1.
/// </summary>
protected override int VisualChildrenCount
{
get { return 1; }
}
/// <summary>
/// Override. Always returns 1.
/// </summary>
protected override int VisualChildrenCount
{
get { return 1; }
}
#endregion // Protected Overrides
#endregion // Protected Overrides
#region Private Helpers
#region Private Helpers
private void UpdateLocation()
{
AdornerLayer adornerLayer = this.Parent as AdornerLayer;
if( adornerLayer != null )
adornerLayer.Update( this.AdornedElement );
}
private void UpdateLocation()
{
AdornerLayer adornerLayer = this.Parent as AdornerLayer;
if (adornerLayer != null)
adornerLayer.Update(this.AdornedElement);
}
#endregion // Private Helpers
}
#endregion // Private Helpers
}
}

View File

@@ -1,13 +1,7 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Runtime.InteropServices;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Runtime.InteropServices;
using System.Windows.Media.Imaging;
namespace GeekDesk.Util
@@ -46,7 +40,7 @@ namespace GeekDesk.Util
Bitmap bmp = ico.ToBitmap();
MemoryStream strm = new MemoryStream();
bmp.Save(strm, System.Drawing.Imaging.ImageFormat.Png);
BitmapImage bmpImage = new BitmapImage();
BitmapImage bmpImage = new BitmapImage();
bmpImage.BeginInit();
strm.Seek(0, SeekOrigin.Begin);
bmpImage.StreamSource = strm;

File diff suppressed because it is too large Load Diff

View File

@@ -1,9 +1,5 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Data;
namespace GeekDesk.Util
@@ -12,10 +8,11 @@ namespace GeekDesk.Util
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value != null && value.ToString().Length>0)
if (value != null && value.ToString().Length > 0)
{
return System.Convert.ToDouble(value.ToString()) - 10d;
} else
}
else
{
return 0d;
}

View File

@@ -1,58 +1,56 @@
using System;
using System.Collections.Generic;
using System.Text;
using System.Runtime.InteropServices;
using System.Windows;
using System.Windows.Media;
namespace WPF.JoshSmith.Controls.Utilities
{
/// <summary>
/// Provides access to the mouse location by calling unmanaged code.
/// </summary>
/// <remarks>
/// This class was written by Dan Crevier (Microsoft).
/// http://blogs.msdn.com/llobo/archive/2006/09/06/Scrolling-Scrollviewer-on-Mouse-Drag-at-the-boundaries.aspx
/// </remarks>
public class MouseUtilities
{
[StructLayout( LayoutKind.Sequential )]
private struct Win32Point
{
public Int32 X;
public Int32 Y;
};
/// <summary>
/// Provides access to the mouse location by calling unmanaged code.
/// </summary>
/// <remarks>
/// This class was written by Dan Crevier (Microsoft).
/// http://blogs.msdn.com/llobo/archive/2006/09/06/Scrolling-Scrollviewer-on-Mouse-Drag-at-the-boundaries.aspx
/// </remarks>
public class MouseUtilities
{
[StructLayout(LayoutKind.Sequential)]
private struct Win32Point
{
public Int32 X;
public Int32 Y;
};
[DllImport( "user32.dll" )]
private static extern bool GetCursorPos( ref Win32Point pt );
[DllImport("user32.dll")]
private static extern bool GetCursorPos(ref Win32Point pt);
[DllImport( "user32.dll" )]
private static extern bool ScreenToClient( IntPtr hwnd, ref Win32Point pt );
[DllImport("user32.dll")]
private static extern bool ScreenToClient(IntPtr hwnd, ref Win32Point pt);
/// <summary>
/// Returns the mouse cursor location. This method is necessary during
/// a drag-drop operation because the WPF mechanisms for retrieving the
/// cursor coordinates are unreliable.
/// </summary>
/// <param name="relativeTo">The Visual to which the mouse coordinates will be relative.</param>
public static Point GetMousePosition( Visual relativeTo )
{
Win32Point mouse = new Win32Point();
GetCursorPos( ref mouse );
/// <summary>
/// Returns the mouse cursor location. This method is necessary during
/// a drag-drop operation because the WPF mechanisms for retrieving the
/// cursor coordinates are unreliable.
/// </summary>
/// <param name="relativeTo">The Visual to which the mouse coordinates will be relative.</param>
public static Point GetMousePosition(Visual relativeTo)
{
Win32Point mouse = new Win32Point();
GetCursorPos(ref mouse);
// Using PointFromScreen instead of Dan Crevier's code (commented out below)
// is a bug fix created by William J. Roberts. Read his comments about the fix
// here: http://www.codeproject.com/useritems/ListViewDragDropManager.asp?msg=1911611#xx1911611xx
return relativeTo.PointFromScreen( new Point( (double)mouse.X, (double)mouse.Y ) );
// Using PointFromScreen instead of Dan Crevier's code (commented out below)
// is a bug fix created by William J. Roberts. Read his comments about the fix
// here: http://www.codeproject.com/useritems/ListViewDragDropManager.asp?msg=1911611#xx1911611xx
return relativeTo.PointFromScreen(new Point((double)mouse.X, (double)mouse.Y));
#region Commented Out
//System.Windows.Interop.HwndSource presentationSource =
// (System.Windows.Interop.HwndSource)PresentationSource.FromVisual( relativeTo );
//ScreenToClient( presentationSource.Handle, ref mouse );
//GeneralTransform transform = relativeTo.TransformToAncestor( presentationSource.RootVisual );
//Point offset = transform.Transform( new Point( 0, 0 ) );
//return new Point( mouse.X - offset.X, mouse.Y - offset.Y );
#endregion // Commented Out
}
}
#region Commented Out
//System.Windows.Interop.HwndSource presentationSource =
// (System.Windows.Interop.HwndSource)PresentationSource.FromVisual( relativeTo );
//ScreenToClient( presentationSource.Handle, ref mouse );
//GeneralTransform transform = relativeTo.TransformToAncestor( presentationSource.RootVisual );
//Point offset = transform.Transform( new Point( 0, 0 ) );
//return new Point( mouse.X - offset.X, mouse.Y - offset.Y );
#endregion // Commented Out
}
}
}

View File

@@ -1,13 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Drawing;
using Microsoft.Win32;
using System.Runtime.InteropServices;
using System.Drawing.Imaging;
using GeekDesk.Util;
namespace GeekDesk.Util
{

View File

@@ -1,15 +1,13 @@
using GalaSoft.MvvmLight;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

using GeekDesk.Constant;
using System;
using System.ComponentModel;
namespace GeekDesk.ViewModel
{
[Serializable]
public class AppConfig : ViewModelBase
public class AppConfig : System.ComponentModel.INotifyPropertyChanged
{
private int menuSortType = (int)SortType.CUSTOM; //菜单排序类型
private int iconSortType = (int)SortType.CUSTOM; //图表排序类型
@@ -18,8 +16,10 @@ namespace GeekDesk.ViewModel
private double menuCardWidth = (double)DefaultConstant.MENU_CARD_WIDHT;//菜单栏宽度
#region GetSet
public int MenuSortType {
public int MenuSortType
{
get
{
return menuSortType;
@@ -27,7 +27,7 @@ namespace GeekDesk.ViewModel
set
{
menuSortType = value;
RaisePropertyChanged();
OnPropertyChanged("MenuSortType");
}
}
@@ -40,7 +40,7 @@ namespace GeekDesk.ViewModel
set
{
iconSortType = value;
RaisePropertyChanged();
OnPropertyChanged("IconSortType");
}
}
@@ -53,7 +53,7 @@ namespace GeekDesk.ViewModel
set
{
windowWidth = value;
RaisePropertyChanged();
OnPropertyChanged("WindowWidth");
}
}
@@ -66,7 +66,7 @@ namespace GeekDesk.ViewModel
set
{
windowHeight = value;
RaisePropertyChanged();
OnPropertyChanged("WindowHeight");
}
}
@@ -79,9 +79,17 @@ namespace GeekDesk.ViewModel
set
{
menuCardWidth = value;
RaisePropertyChanged();
OnPropertyChanged("MenuCardWidth");
}
}
[field: NonSerializedAttribute()]
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
#endregion
}

61
ViewModel/AppData.cs Normal file
View File

@@ -0,0 +1,61 @@
using System;
using System.Collections.Generic;
using System.ComponentModel;
namespace GeekDesk.ViewModel
{
[Serializable]
class AppData : INotifyPropertyChanged
{
private List<string> menuList = new List<string>();
private Dictionary<string, List<IconInfo>> iconMap = new Dictionary<string, List<IconInfo>>();
private AppConfig appConfig = new AppConfig();
public List<string> MenuList
{
get
{
return menuList;
}
set
{
menuList = value;
OnPropertyChanged("MenuList");
}
}
public Dictionary<string, List<IconInfo>> IconMap
{
get
{
return iconMap;
}
set
{
iconMap = value;
OnPropertyChanged("IconMap");
}
}
public AppConfig AppConfig
{
get
{
return appConfig;
}
set
{
appConfig = value;
OnPropertyChanged("AppConfig");
}
}
[field: NonSerializedAttribute()]
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
}
}

View File

@@ -1,70 +0,0 @@
using GalaSoft.MvvmLight;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Media.Imaging;
namespace GeekDesk.ViewModel
{
public class DataInfos : ViewModelBase
{
private string path; //路径
private string name; //文件名
private int count = 0; //打开次数
private BitmapImage bitmapImage; //位图
public int Count
{
get
{
return count;
}
set
{
count = value;
RaisePropertyChanged();
}
}
public string Name
{
get
{
return name;
}
set
{
name = value;
RaisePropertyChanged();
}
}
public string Path
{
get
{
return path;
}
set
{
path = value;
RaisePropertyChanged();
}
}
public BitmapImage BitmapImage
{
get
{
return bitmapImage;
}
set
{
bitmapImage = value;
RaisePropertyChanged();
}
}
}
}

137
ViewModel/IconInfo.cs Normal file
View File

@@ -0,0 +1,137 @@
using System;
using System.ComponentModel;
using System.IO;
using System.Windows.Media.Imaging;
namespace GeekDesk.ViewModel
{
[Serializable]
public class IconInfo : INotifyPropertyChanged
{
private string path; //路径
private string name; //文件名
private int count = 0; //打开次数
[field: NonSerialized]
private BitmapImage bitmapImage; //位图
private byte[] imageByteArr; //图片 base64
private string content; //显示信息
public int Count
{
get
{
return count;
}
set
{
count = value;
Content = Path + "\n" + Name + "\n使用次数: " + Count;
OnPropertyChanged("Count");
}
}
public string Name
{
get
{
return name;
}
set
{
name = value;
Content = Path + "\n" + Name + "\n使用次数: " + Count;
OnPropertyChanged("Name");
}
}
public string Path
{
get
{
return path;
}
set
{
path = value;
Content = Path + "\n" + Name + "\n使用次数: " + Count;
OnPropertyChanged("Path");
}
}
public BitmapImage BitmapImage
{
get
{
return ToImage(ImageByteArr);
}
set
{
bitmapImage = value;
ImageByteArr = getJPGFromImageControl(bitmapImage);
OnPropertyChanged("BitmapImage");
}
}
public byte[] ImageByteArr
{
get
{
return imageByteArr;
}
set
{
imageByteArr = value;
OnPropertyChanged("ImageByteArr");
}
}
public string Content
{
get
{
return content;
}
set
{
content = value;
OnPropertyChanged("Content");
}
}
[field: NonSerializedAttribute()]
public event PropertyChangedEventHandler PropertyChanged;
private void OnPropertyChanged(string propertyName)
{
PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));
}
public BitmapImage ToImage(byte[] array)
{
using (var ms = new System.IO.MemoryStream(array))
{
var image = new BitmapImage();
image.BeginInit();
image.CacheOption = BitmapCacheOption.OnLoad; // here
image.StreamSource = ms;
image.EndInit();
return image;
}
}
public byte[] getJPGFromImageControl(BitmapImage bi)
{
using (MemoryStream memStream = new MemoryStream())
{
PngBitmapEncoder encoder = new PngBitmapEncoder();
encoder.Frames.Add(BitmapFrame.Create(bi));
encoder.Save(memStream);
return memStream.GetBuffer();
}
}
}
}

View File

@@ -1,12 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace GeekDesk.ViewModel
{
class MainModel
{
}
}

View File

@@ -1,34 +0,0 @@
using GalaSoft.MvvmLight;
namespace GeekDesk.ViewModel
{
/// <summary>
/// This class contains properties that the main View can data bind to.
/// <para>
/// Use the <strong>mvvminpc</strong> snippet to add bindable properties to this ViewModel.
/// </para>
/// <para>
/// You can also use Blend to data bind with the tool's support.
/// </para>
/// <para>
/// See http://www.galasoft.ch/mvvm
/// </para>
/// </summary>
public class MainViewModel : ViewModelBase
{
/// <summary>
/// Initializes a new instance of the MainViewModel class.
/// </summary>
public MainViewModel()
{
////if (IsInDesignMode)
////{
//// // Code runs in Blend --> create design time data.
////}
////else
////{
//// // Code runs "for real"
////}
}
}
}

View File

@@ -1,9 +1,4 @@
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Collections.ObjectModel;
namespace GeekDesk.ViewModel
{