1.0beta
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
13
Constant/AppConstant.cs
Normal 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数据文件路径
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -2,11 +2,8 @@
|
||||
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
|
||||
{
|
||||
@@ -23,7 +20,8 @@ namespace DraggAnimatedPanel
|
||||
#region private
|
||||
UIElement __draggedElement;
|
||||
|
||||
public UIElement _draggedElement {
|
||||
public UIElement _draggedElement
|
||||
{
|
||||
get { return __draggedElement; }
|
||||
set
|
||||
{
|
||||
@@ -41,7 +39,7 @@ namespace DraggAnimatedPanel
|
||||
if (_firstScrollRequest && _scrollContainer == null)
|
||||
{
|
||||
_firstScrollRequest = false;
|
||||
_scrollContainer = (ScrollViewer)GetParent(this as DependencyObject, (ve)=>ve is ScrollViewer);
|
||||
_scrollContainer = (ScrollViewer)GetParent(this as DependencyObject, (ve) => ve is ScrollViewer);
|
||||
}
|
||||
return _scrollContainer;
|
||||
}
|
||||
@@ -58,7 +56,7 @@ namespace DraggAnimatedPanel
|
||||
#endregion
|
||||
|
||||
|
||||
void OnMouseMove(object sender,MouseEventArgs e)
|
||||
void OnMouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (e.LeftButton == MouseButtonState.Pressed && _draggedElement == null && !this.IsMouseCaptured)
|
||||
StartDrag(e);
|
||||
@@ -92,11 +90,11 @@ namespace DraggAnimatedPanel
|
||||
_y += difY;
|
||||
//lines ends
|
||||
|
||||
AnimateTo(_draggedElement,_x,_y, 0);
|
||||
AnimateTo(_draggedElement, _x, _y, 0);
|
||||
_lastMousePosX = mousePos.X;
|
||||
_lastMousePosY = mousePos.Y;
|
||||
_lastMouseMoveTime = e.Timestamp;
|
||||
SwapElement(_x + ItemsWidth/2 , _y + ItemsHeight/2);
|
||||
SwapElement(_x + ItemsWidth / 2, _y + ItemsHeight / 2);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -111,7 +109,7 @@ namespace DraggAnimatedPanel
|
||||
Point p = GetItemVisualPoint(_draggedElement);
|
||||
_x = p.X;
|
||||
_y = p.Y;
|
||||
SetZIndex(_draggedElement,1000);
|
||||
SetZIndex(_draggedElement, 1000);
|
||||
_lastMousePosX = mousePos.X;
|
||||
_lastMousePosY = mousePos.Y;
|
||||
_lastMouseMoveTime = e.Timestamp;
|
||||
@@ -120,7 +118,7 @@ namespace DraggAnimatedPanel
|
||||
this.CaptureMouse();
|
||||
}
|
||||
|
||||
void OnMouseUp(object sender,MouseEventArgs e)
|
||||
void OnMouseUp(object sender, MouseEventArgs e)
|
||||
{
|
||||
if (this.IsMouseCaptured)
|
||||
ReleaseMouseCapture();
|
||||
@@ -128,13 +126,13 @@ namespace DraggAnimatedPanel
|
||||
|
||||
void SwapElement(double x, double y)
|
||||
{
|
||||
int index = GetIndexFromPoint(x,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};
|
||||
int[] parameter = new int[] { _draggedIndex, index };
|
||||
if (SwapCommand != null && SwapCommand.CanExecute(parameter))
|
||||
{
|
||||
SwapCommand.Execute(parameter);
|
||||
@@ -155,11 +153,11 @@ namespace DraggAnimatedPanel
|
||||
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)
|
||||
void OnLostMouseCapture(object sender, MouseEventArgs e)
|
||||
{
|
||||
FinishDrag();
|
||||
}
|
||||
@@ -168,7 +166,7 @@ namespace DraggAnimatedPanel
|
||||
{
|
||||
if (_draggedElement != null)
|
||||
{
|
||||
SetZIndex(_draggedElement,0);
|
||||
SetZIndex(_draggedElement, 0);
|
||||
_draggedElement = null;
|
||||
this.InvalidateArrange();
|
||||
}
|
||||
|
||||
@@ -1,14 +1,11 @@
|
||||
/*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
|
||||
{
|
||||
|
||||
@@ -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>
|
||||
|
||||
@@ -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}"/>
|
||||
|
||||
@@ -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);
|
||||
foreach (object obj in dropObject)
|
||||
{
|
||||
string path = (string)obj;
|
||||
if (File.Exists(path))
|
||||
{
|
||||
// 文件
|
||||
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();
|
||||
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; }
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System.Reflection;
|
||||
using System.Resources;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
// 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
|
||||
{
|
||||
@@ -33,8 +28,8 @@ namespace WPF.JoshSmith.Adorners
|
||||
/// <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 )
|
||||
public DragAdorner(UIElement adornedElement, Size size, Brush brush)
|
||||
: base(adornedElement)
|
||||
{
|
||||
Rectangle rect = new Rectangle();
|
||||
rect.Fill = brush;
|
||||
@@ -55,11 +50,11 @@ namespace WPF.JoshSmith.Adorners
|
||||
/// </summary>
|
||||
/// <param name="transform"></param>
|
||||
/// <returns></returns>
|
||||
public override GeneralTransform GetDesiredTransform( GeneralTransform transform )
|
||||
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 ) );
|
||||
result.Children.Add(base.GetDesiredTransform(transform));
|
||||
result.Children.Add(new TranslateTransform(this.offsetLeft, this.offsetTop));
|
||||
return result;
|
||||
}
|
||||
|
||||
@@ -89,7 +84,7 @@ namespace WPF.JoshSmith.Adorners
|
||||
/// </summary>
|
||||
/// <param name="left"></param>
|
||||
/// <param name="top"></param>
|
||||
public void SetOffsets( double left, double top )
|
||||
public void SetOffsets(double left, double top)
|
||||
{
|
||||
this.offsetLeft = left;
|
||||
this.offsetTop = top;
|
||||
@@ -124,9 +119,9 @@ namespace WPF.JoshSmith.Adorners
|
||||
/// </summary>
|
||||
/// <param name="constraint"></param>
|
||||
/// <returns></returns>
|
||||
protected override Size MeasureOverride( Size constraint )
|
||||
protected override Size MeasureOverride(Size constraint)
|
||||
{
|
||||
this.child.Measure( constraint );
|
||||
this.child.Measure(constraint);
|
||||
return this.child.DesiredSize;
|
||||
}
|
||||
|
||||
@@ -135,9 +130,9 @@ namespace WPF.JoshSmith.Adorners
|
||||
/// </summary>
|
||||
/// <param name="finalSize"></param>
|
||||
/// <returns></returns>
|
||||
protected override Size ArrangeOverride( Size finalSize )
|
||||
protected override Size ArrangeOverride(Size finalSize)
|
||||
{
|
||||
this.child.Arrange( new Rect( finalSize ) );
|
||||
this.child.Arrange(new Rect(finalSize));
|
||||
return finalSize;
|
||||
}
|
||||
|
||||
@@ -146,7 +141,7 @@ namespace WPF.JoshSmith.Adorners
|
||||
/// </summary>
|
||||
/// <param name="index"></param>
|
||||
/// <returns></returns>
|
||||
protected override Visual GetVisualChild( int index )
|
||||
protected override Visual GetVisualChild(int index)
|
||||
{
|
||||
return this.child;
|
||||
}
|
||||
@@ -166,8 +161,8 @@ namespace WPF.JoshSmith.Adorners
|
||||
private void UpdateLocation()
|
||||
{
|
||||
AdornerLayer adornerLayer = this.Parent as AdornerLayer;
|
||||
if( adornerLayer != null )
|
||||
adornerLayer.Update( this.AdornedElement );
|
||||
if (adornerLayer != null)
|
||||
adornerLayer.Update(this.AdornedElement);
|
||||
}
|
||||
|
||||
#endregion // Private Helpers
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -1,14 +1,12 @@
|
||||
// Copyright (C) Josh Smith - January 2007
|
||||
using System;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Diagnostics;
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Controls.Primitives;
|
||||
using System.Windows.Documents;
|
||||
using System.Windows.Media;
|
||||
using System.Windows.Input;
|
||||
using System.Windows.Media;
|
||||
using WPF.JoshSmith.Adorners;
|
||||
using WPF.JoshSmith.Controls.Utilities;
|
||||
|
||||
@@ -57,7 +55,7 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
/// Initializes a new instance of ListViewDragManager.
|
||||
/// </summary>
|
||||
/// <param name="listView"></param>
|
||||
public ListViewDragDropManager( ListView listView )
|
||||
public ListViewDragDropManager(ListView listView)
|
||||
: this()
|
||||
{
|
||||
this.ListView = listView;
|
||||
@@ -68,8 +66,8 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
/// </summary>
|
||||
/// <param name="listView"></param>
|
||||
/// <param name="dragAdornerOpacity"></param>
|
||||
public ListViewDragDropManager( ListView listView, double dragAdornerOpacity )
|
||||
: this( listView )
|
||||
public ListViewDragDropManager(ListView listView, double dragAdornerOpacity)
|
||||
: this(listView)
|
||||
{
|
||||
this.DragAdornerOpacity = dragAdornerOpacity;
|
||||
}
|
||||
@@ -79,8 +77,8 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
/// </summary>
|
||||
/// <param name="listView"></param>
|
||||
/// <param name="showDragAdorner"></param>
|
||||
public ListViewDragDropManager( ListView listView, bool showDragAdorner )
|
||||
: this( listView )
|
||||
public ListViewDragDropManager(ListView listView, bool showDragAdorner)
|
||||
: this(listView)
|
||||
{
|
||||
this.ShowDragAdorner = showDragAdorner;
|
||||
}
|
||||
@@ -100,11 +98,11 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
get { return this.dragAdornerOpacity; }
|
||||
set
|
||||
{
|
||||
if( this.IsDragInProgress )
|
||||
throw new InvalidOperationException( "Cannot set the DragAdornerOpacity property during a drag operation." );
|
||||
if (this.IsDragInProgress)
|
||||
throw new InvalidOperationException("Cannot set the DragAdornerOpacity property during a drag operation.");
|
||||
|
||||
if( value < 0.0 || value > 1.0 )
|
||||
throw new ArgumentOutOfRangeException( "DragAdornerOpacity", value, "Must be between 0 and 1." );
|
||||
if (value < 0.0 || value > 1.0)
|
||||
throw new ArgumentOutOfRangeException("DragAdornerOpacity", value, "Must be between 0 and 1.");
|
||||
|
||||
this.dragAdornerOpacity = value;
|
||||
}
|
||||
@@ -137,10 +135,10 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
get { return listView; }
|
||||
set
|
||||
{
|
||||
if( this.IsDragInProgress )
|
||||
throw new InvalidOperationException( "Cannot set the ListView property during a drag operation." );
|
||||
if (this.IsDragInProgress)
|
||||
throw new InvalidOperationException("Cannot set the ListView property during a drag operation.");
|
||||
|
||||
if( this.listView != null )
|
||||
if (this.listView != null)
|
||||
{
|
||||
#region Unhook Events
|
||||
|
||||
@@ -156,9 +154,9 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
|
||||
this.listView = value;
|
||||
|
||||
if( this.listView != null )
|
||||
if (this.listView != null)
|
||||
{
|
||||
if( !this.listView.AllowDrop )
|
||||
if (!this.listView.AllowDrop)
|
||||
this.listView.AllowDrop = true;
|
||||
|
||||
#region Hook Events
|
||||
@@ -200,8 +198,8 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
get { return this.showDragAdorner; }
|
||||
set
|
||||
{
|
||||
if( this.IsDragInProgress )
|
||||
throw new InvalidOperationException( "Cannot set the ShowDragAdorner property during a drag operation." );
|
||||
if (this.IsDragInProgress)
|
||||
throw new InvalidOperationException("Cannot set the ShowDragAdorner property during a drag operation.");
|
||||
|
||||
this.showDragAdorner = value;
|
||||
}
|
||||
@@ -215,9 +213,9 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
|
||||
#region listView_PreviewMouseLeftButtonDown
|
||||
|
||||
void listView_PreviewMouseLeftButtonDown( object sender, MouseButtonEventArgs e )
|
||||
void listView_PreviewMouseLeftButtonDown(object sender, MouseButtonEventArgs e)
|
||||
{
|
||||
if( this.IsMouseOverScrollbar )
|
||||
if (this.IsMouseOverScrollbar)
|
||||
{
|
||||
// 4/13/2007 - Set the flag to false when cursor is over scrollbar.
|
||||
this.canInitiateDrag = false;
|
||||
@@ -227,15 +225,15 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
int index = this.IndexUnderDragCursor;
|
||||
this.canInitiateDrag = index > -1;
|
||||
|
||||
if( this.canInitiateDrag )
|
||||
if (this.canInitiateDrag)
|
||||
{
|
||||
// Remember the location and index of the ListViewItem the user clicked on for later.
|
||||
this.ptMouseDown = MouseUtilities.GetMousePosition( this.listView );
|
||||
this.ptMouseDown = MouseUtilities.GetMousePosition(this.listView);
|
||||
this.indexToSelect = index;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ptMouseDown = new Point( -10000, -10000 );
|
||||
this.ptMouseDown = new Point(-10000, -10000);
|
||||
this.indexToSelect = -1;
|
||||
}
|
||||
}
|
||||
@@ -244,40 +242,40 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
|
||||
#region listView_PreviewMouseMove
|
||||
|
||||
void listView_PreviewMouseMove( object sender, MouseEventArgs e )
|
||||
void listView_PreviewMouseMove(object sender, MouseEventArgs e)
|
||||
{
|
||||
if( !this.CanStartDragOperation )
|
||||
if (!this.CanStartDragOperation)
|
||||
return;
|
||||
|
||||
// Select the item the user clicked on.
|
||||
if( this.listView.SelectedIndex != this.indexToSelect )
|
||||
if (this.listView.SelectedIndex != this.indexToSelect)
|
||||
this.listView.SelectedIndex = this.indexToSelect;
|
||||
|
||||
// If the item at the selected index is null, there's nothing
|
||||
// we can do, so just return;
|
||||
if( this.listView.SelectedItem == null )
|
||||
if (this.listView.SelectedItem == null)
|
||||
return;
|
||||
|
||||
ListViewItem itemToDrag = this.GetListViewItem( this.listView.SelectedIndex );
|
||||
if( itemToDrag == null )
|
||||
ListViewItem itemToDrag = this.GetListViewItem(this.listView.SelectedIndex);
|
||||
if (itemToDrag == null)
|
||||
return;
|
||||
|
||||
AdornerLayer adornerLayer = this.ShowDragAdornerResolved ? this.InitializeAdornerLayer( itemToDrag ) : null;
|
||||
AdornerLayer adornerLayer = this.ShowDragAdornerResolved ? this.InitializeAdornerLayer(itemToDrag) : null;
|
||||
|
||||
this.InitializeDragOperation( itemToDrag );
|
||||
this.InitializeDragOperation(itemToDrag);
|
||||
this.PerformDragOperation();
|
||||
this.FinishDragOperation( itemToDrag, adornerLayer );
|
||||
this.FinishDragOperation(itemToDrag, adornerLayer);
|
||||
}
|
||||
|
||||
#endregion // listView_PreviewMouseMove
|
||||
|
||||
#region listView_DragOver
|
||||
|
||||
void listView_DragOver( object sender, DragEventArgs e )
|
||||
void listView_DragOver(object sender, DragEventArgs e)
|
||||
{
|
||||
e.Effects = DragDropEffects.Move;
|
||||
|
||||
if( this.ShowDragAdornerResolved )
|
||||
if (this.ShowDragAdornerResolved)
|
||||
this.UpdateDragAdornerLocation();
|
||||
|
||||
// Update the item which is known to be currently under the drag cursor.
|
||||
@@ -289,14 +287,14 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
|
||||
#region listView_DragLeave
|
||||
|
||||
void listView_DragLeave( object sender, DragEventArgs e )
|
||||
void listView_DragLeave(object sender, DragEventArgs e)
|
||||
{
|
||||
if( !this.IsMouseOver( this.listView ) )
|
||||
if (!this.IsMouseOver(this.listView))
|
||||
{
|
||||
if( this.ItemUnderDragCursor != null )
|
||||
if (this.ItemUnderDragCursor != null)
|
||||
this.ItemUnderDragCursor = null;
|
||||
|
||||
if( this.dragAdorner != null )
|
||||
if (this.dragAdorner != null)
|
||||
this.dragAdorner.Visibility = Visibility.Collapsed;
|
||||
}
|
||||
}
|
||||
@@ -305,9 +303,9 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
|
||||
#region listView_DragEnter
|
||||
|
||||
void listView_DragEnter( object sender, DragEventArgs e )
|
||||
void listView_DragEnter(object sender, DragEventArgs e)
|
||||
{
|
||||
if( this.dragAdorner != null && this.dragAdorner.Visibility != Visibility.Visible )
|
||||
if (this.dragAdorner != null && this.dragAdorner.Visibility != Visibility.Visible)
|
||||
{
|
||||
// Update the location of the adorner and then show it.
|
||||
this.UpdateDragAdornerLocation();
|
||||
@@ -319,40 +317,40 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
|
||||
#region listView_Drop
|
||||
|
||||
void listView_Drop( object sender, DragEventArgs e )
|
||||
void listView_Drop(object sender, DragEventArgs e)
|
||||
{
|
||||
if( this.ItemUnderDragCursor != null )
|
||||
if (this.ItemUnderDragCursor != null)
|
||||
this.ItemUnderDragCursor = null;
|
||||
|
||||
e.Effects = DragDropEffects.None;
|
||||
|
||||
if( !e.Data.GetDataPresent( typeof( ItemType ) ) )
|
||||
if (!e.Data.GetDataPresent(typeof(ItemType)))
|
||||
return;
|
||||
|
||||
// Get the data object which was dropped.
|
||||
ItemType data = e.Data.GetData( typeof( ItemType ) ) as ItemType;
|
||||
if( data == null )
|
||||
ItemType data = e.Data.GetData(typeof(ItemType)) as ItemType;
|
||||
if (data == null)
|
||||
return;
|
||||
|
||||
// Get the ObservableCollection<ItemType> which contains the dropped data object.
|
||||
ObservableCollection<ItemType> itemsSource = this.listView.ItemsSource as ObservableCollection<ItemType>;
|
||||
if( itemsSource == null )
|
||||
if (itemsSource == null)
|
||||
throw new Exception(
|
||||
"A ListView managed by ListViewDragManager must have its ItemsSource set to an ObservableCollection<ItemType>." );
|
||||
"A ListView managed by ListViewDragManager must have its ItemsSource set to an ObservableCollection<ItemType>.");
|
||||
|
||||
int oldIndex = itemsSource.IndexOf( data );
|
||||
int oldIndex = itemsSource.IndexOf(data);
|
||||
int newIndex = this.IndexUnderDragCursor;
|
||||
|
||||
if( newIndex < 0 )
|
||||
if (newIndex < 0)
|
||||
{
|
||||
// The drag started somewhere else, and our ListView is empty
|
||||
// so make the new item the first in the list.
|
||||
if( itemsSource.Count == 0 )
|
||||
if (itemsSource.Count == 0)
|
||||
newIndex = 0;
|
||||
|
||||
// The drag started somewhere else, but our ListView has items
|
||||
// so make the new item the last in the list.
|
||||
else if( oldIndex < 0 )
|
||||
else if (oldIndex < 0)
|
||||
newIndex = itemsSource.Count;
|
||||
|
||||
// The user is trying to drop an item from our ListView into
|
||||
@@ -363,14 +361,14 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
}
|
||||
|
||||
// Dropping an item back onto itself is not considered an actual 'drop'.
|
||||
if( oldIndex == newIndex )
|
||||
if (oldIndex == newIndex)
|
||||
return;
|
||||
|
||||
if( this.ProcessDrop != null )
|
||||
if (this.ProcessDrop != null)
|
||||
{
|
||||
// Let the client code process the drop.
|
||||
ProcessDropEventArgs<ItemType> args = new ProcessDropEventArgs<ItemType>( itemsSource, data, oldIndex, newIndex, e.AllowedEffects );
|
||||
this.ProcessDrop( this, args );
|
||||
ProcessDropEventArgs<ItemType> args = new ProcessDropEventArgs<ItemType>(itemsSource, data, oldIndex, newIndex, e.AllowedEffects);
|
||||
this.ProcessDrop(this, args);
|
||||
e.Effects = args.Effects;
|
||||
}
|
||||
else
|
||||
@@ -378,10 +376,10 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
// Move the dragged data object from it's original index to the
|
||||
// new index (according to where the mouse cursor is). If it was
|
||||
// not previously in the ListBox, then insert the item.
|
||||
if( oldIndex > -1 )
|
||||
itemsSource.Move( oldIndex, newIndex );
|
||||
if (oldIndex > -1)
|
||||
itemsSource.Move(oldIndex, newIndex);
|
||||
else
|
||||
itemsSource.Insert( newIndex, data );
|
||||
itemsSource.Insert(newIndex, data);
|
||||
|
||||
// Set the Effects property so that the call to DoDragDrop will return 'Move'.
|
||||
e.Effects = DragDropEffects.Move;
|
||||
@@ -400,16 +398,16 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
{
|
||||
get
|
||||
{
|
||||
if( Mouse.LeftButton != MouseButtonState.Pressed )
|
||||
if (Mouse.LeftButton != MouseButtonState.Pressed)
|
||||
return false;
|
||||
|
||||
if( !this.canInitiateDrag )
|
||||
if (!this.canInitiateDrag)
|
||||
return false;
|
||||
|
||||
if( this.indexToSelect == -1 )
|
||||
if (this.indexToSelect == -1)
|
||||
return false;
|
||||
|
||||
if( !this.HasCursorLeftDragThreshold )
|
||||
if (!this.HasCursorLeftDragThreshold)
|
||||
return false;
|
||||
|
||||
return true;
|
||||
@@ -420,20 +418,20 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
|
||||
#region FinishDragOperation
|
||||
|
||||
void FinishDragOperation( ListViewItem draggedItem, AdornerLayer adornerLayer )
|
||||
void FinishDragOperation(ListViewItem draggedItem, AdornerLayer adornerLayer)
|
||||
{
|
||||
// Let the ListViewItem know that it is not being dragged anymore.
|
||||
ListViewItemDragState.SetIsBeingDragged( draggedItem, false );
|
||||
ListViewItemDragState.SetIsBeingDragged(draggedItem, false);
|
||||
|
||||
this.IsDragInProgress = false;
|
||||
|
||||
if( this.ItemUnderDragCursor != null )
|
||||
if (this.ItemUnderDragCursor != null)
|
||||
this.ItemUnderDragCursor = null;
|
||||
|
||||
// Remove the drag adorner from the adorner layer.
|
||||
if( adornerLayer != null )
|
||||
if (adornerLayer != null)
|
||||
{
|
||||
adornerLayer.Remove( this.dragAdorner );
|
||||
adornerLayer.Remove(this.dragAdorner);
|
||||
this.dragAdorner = null;
|
||||
}
|
||||
}
|
||||
@@ -442,20 +440,20 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
|
||||
#region GetListViewItem
|
||||
|
||||
ListViewItem GetListViewItem( int index )
|
||||
ListViewItem GetListViewItem(int index)
|
||||
{
|
||||
if( this.listView.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated )
|
||||
if (this.listView.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated)
|
||||
return null;
|
||||
|
||||
return this.listView.ItemContainerGenerator.ContainerFromIndex( index ) as ListViewItem;
|
||||
return this.listView.ItemContainerGenerator.ContainerFromIndex(index) as ListViewItem;
|
||||
}
|
||||
|
||||
ListViewItem GetListViewItem( ItemType dataItem )
|
||||
ListViewItem GetListViewItem(ItemType dataItem)
|
||||
{
|
||||
if( this.listView.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated )
|
||||
if (this.listView.ItemContainerGenerator.Status != GeneratorStatus.ContainersGenerated)
|
||||
return null;
|
||||
|
||||
return this.listView.ItemContainerGenerator.ContainerFromItem( dataItem ) as ListViewItem;
|
||||
return this.listView.ItemContainerGenerator.ContainerFromItem(dataItem) as ListViewItem;
|
||||
}
|
||||
|
||||
#endregion // GetListViewItem
|
||||
@@ -466,28 +464,28 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
{
|
||||
get
|
||||
{
|
||||
if( this.indexToSelect < 0 )
|
||||
if (this.indexToSelect < 0)
|
||||
return false;
|
||||
|
||||
ListViewItem item = this.GetListViewItem( this.indexToSelect );
|
||||
Rect bounds = VisualTreeHelper.GetDescendantBounds( item );
|
||||
Point ptInItem = this.listView.TranslatePoint( this.ptMouseDown, item );
|
||||
ListViewItem item = this.GetListViewItem(this.indexToSelect);
|
||||
Rect bounds = VisualTreeHelper.GetDescendantBounds(item);
|
||||
Point ptInItem = this.listView.TranslatePoint(this.ptMouseDown, item);
|
||||
|
||||
// In case the cursor is at the very top or bottom of the ListViewItem
|
||||
// we want to make the vertical threshold very small so that dragging
|
||||
// over an adjacent item does not select it.
|
||||
double topOffset = Math.Abs( ptInItem.Y );
|
||||
double btmOffset = Math.Abs( bounds.Height - ptInItem.Y );
|
||||
double vertOffset = Math.Min( topOffset, btmOffset );
|
||||
double topOffset = Math.Abs(ptInItem.Y);
|
||||
double btmOffset = Math.Abs(bounds.Height - ptInItem.Y);
|
||||
double vertOffset = Math.Min(topOffset, btmOffset);
|
||||
|
||||
double width = SystemParameters.MinimumHorizontalDragDistance * 2;
|
||||
double height = Math.Min( SystemParameters.MinimumVerticalDragDistance, vertOffset ) * 2;
|
||||
Size szThreshold = new Size( width, height );
|
||||
double height = Math.Min(SystemParameters.MinimumVerticalDragDistance, vertOffset) * 2;
|
||||
Size szThreshold = new Size(width, height);
|
||||
|
||||
Rect rect = new Rect( this.ptMouseDown, szThreshold );
|
||||
rect.Offset( szThreshold.Width / -2, szThreshold.Height / -2 );
|
||||
Point ptInListView = MouseUtilities.GetMousePosition( this.listView );
|
||||
return !rect.Contains( ptInListView );
|
||||
Rect rect = new Rect(this.ptMouseDown, szThreshold);
|
||||
rect.Offset(szThreshold.Width / -2, szThreshold.Height / -2);
|
||||
Point ptInListView = MouseUtilities.GetMousePosition(this.listView);
|
||||
return !rect.Contains(ptInListView);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -504,10 +502,10 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
get
|
||||
{
|
||||
int index = -1;
|
||||
for( int i = 0; i < this.listView.Items.Count; ++i )
|
||||
for (int i = 0; i < this.listView.Items.Count; ++i)
|
||||
{
|
||||
ListViewItem item = this.GetListViewItem( i );
|
||||
if( this.IsMouseOver( item ) )
|
||||
ListViewItem item = this.GetListViewItem(i);
|
||||
if (this.IsMouseOver(item))
|
||||
{
|
||||
index = i;
|
||||
break;
|
||||
@@ -521,23 +519,23 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
|
||||
#region InitializeAdornerLayer
|
||||
|
||||
AdornerLayer InitializeAdornerLayer( ListViewItem itemToDrag )
|
||||
AdornerLayer InitializeAdornerLayer(ListViewItem itemToDrag)
|
||||
{
|
||||
// Create a brush which will paint the ListViewItem onto
|
||||
// a visual in the adorner layer.
|
||||
VisualBrush brush = new VisualBrush( itemToDrag );
|
||||
VisualBrush brush = new VisualBrush(itemToDrag);
|
||||
|
||||
// Create an element which displays the source item while it is dragged.
|
||||
this.dragAdorner = new DragAdorner( this.listView, itemToDrag.RenderSize, brush );
|
||||
this.dragAdorner = new DragAdorner(this.listView, itemToDrag.RenderSize, brush);
|
||||
|
||||
// Set the drag adorner's opacity.
|
||||
this.dragAdorner.Opacity = this.DragAdornerOpacity;
|
||||
|
||||
AdornerLayer layer = AdornerLayer.GetAdornerLayer( this.listView );
|
||||
layer.Add( dragAdorner );
|
||||
AdornerLayer layer = AdornerLayer.GetAdornerLayer(this.listView);
|
||||
layer.Add(dragAdorner);
|
||||
|
||||
// Save the location of the cursor when the left mouse button was pressed.
|
||||
this.ptMouseDown = MouseUtilities.GetMousePosition( this.listView );
|
||||
this.ptMouseDown = MouseUtilities.GetMousePosition(this.listView);
|
||||
|
||||
return layer;
|
||||
}
|
||||
@@ -546,29 +544,29 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
|
||||
#region InitializeDragOperation
|
||||
|
||||
void InitializeDragOperation( ListViewItem itemToDrag )
|
||||
void InitializeDragOperation(ListViewItem itemToDrag)
|
||||
{
|
||||
// Set some flags used during the drag operation.
|
||||
this.IsDragInProgress = true;
|
||||
this.canInitiateDrag = false;
|
||||
|
||||
// Let the ListViewItem know that it is being dragged.
|
||||
ListViewItemDragState.SetIsBeingDragged( itemToDrag, true );
|
||||
ListViewItemDragState.SetIsBeingDragged(itemToDrag, true);
|
||||
}
|
||||
|
||||
#endregion // InitializeDragOperation
|
||||
|
||||
#region IsMouseOver
|
||||
|
||||
bool IsMouseOver( Visual target )
|
||||
bool IsMouseOver(Visual target)
|
||||
{
|
||||
// We need to use MouseUtilities to figure out the cursor
|
||||
// coordinates because, during a drag-drop operation, the WPF
|
||||
// mechanisms for getting the coordinates behave strangely.
|
||||
|
||||
Rect bounds = VisualTreeHelper.GetDescendantBounds( target );
|
||||
Point mousePos = MouseUtilities.GetMousePosition( target );
|
||||
return bounds.Contains( mousePos );
|
||||
Rect bounds = VisualTreeHelper.GetDescendantBounds(target);
|
||||
Point mousePos = MouseUtilities.GetMousePosition(target);
|
||||
return bounds.Contains(mousePos);
|
||||
}
|
||||
|
||||
#endregion // IsMouseOver
|
||||
@@ -582,24 +580,24 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
{
|
||||
get
|
||||
{
|
||||
Point ptMouse = MouseUtilities.GetMousePosition( this.listView );
|
||||
HitTestResult res = VisualTreeHelper.HitTest( this.listView, ptMouse );
|
||||
if( res == null )
|
||||
Point ptMouse = MouseUtilities.GetMousePosition(this.listView);
|
||||
HitTestResult res = VisualTreeHelper.HitTest(this.listView, ptMouse);
|
||||
if (res == null)
|
||||
return false;
|
||||
|
||||
DependencyObject depObj = res.VisualHit;
|
||||
while( depObj != null )
|
||||
while (depObj != null)
|
||||
{
|
||||
if( depObj is ScrollBar )
|
||||
if (depObj is ScrollBar)
|
||||
return true;
|
||||
|
||||
// VisualTreeHelper works with objects of type Visual or Visual3D.
|
||||
// If the current object is not derived from Visual or Visual3D,
|
||||
// then use the LogicalTreeHelper to find the parent element.
|
||||
if( depObj is Visual || depObj is System.Windows.Media.Media3D.Visual3D )
|
||||
depObj = VisualTreeHelper.GetParent( depObj );
|
||||
if (depObj is Visual || depObj is System.Windows.Media.Media3D.Visual3D)
|
||||
depObj = VisualTreeHelper.GetParent(depObj);
|
||||
else
|
||||
depObj = LogicalTreeHelper.GetParent( depObj );
|
||||
depObj = LogicalTreeHelper.GetParent(depObj);
|
||||
}
|
||||
|
||||
return false;
|
||||
@@ -615,21 +613,21 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
get { return this.itemUnderDragCursor; }
|
||||
set
|
||||
{
|
||||
if( this.itemUnderDragCursor == value )
|
||||
if (this.itemUnderDragCursor == value)
|
||||
return;
|
||||
|
||||
// The first pass handles the previous item under the cursor.
|
||||
// The second pass handles the new one.
|
||||
for( int i = 0; i < 2; ++i )
|
||||
for (int i = 0; i < 2; ++i)
|
||||
{
|
||||
if( i == 1 )
|
||||
if (i == 1)
|
||||
this.itemUnderDragCursor = value;
|
||||
|
||||
if( this.itemUnderDragCursor != null )
|
||||
if (this.itemUnderDragCursor != null)
|
||||
{
|
||||
ListViewItem listViewItem = this.GetListViewItem( this.itemUnderDragCursor );
|
||||
if( listViewItem != null )
|
||||
ListViewItemDragState.SetIsUnderDragCursor( listViewItem, i == 1 );
|
||||
ListViewItem listViewItem = this.GetListViewItem(this.itemUnderDragCursor);
|
||||
if (listViewItem != null)
|
||||
ListViewItemDragState.SetIsUnderDragCursor(listViewItem, i == 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -643,7 +641,7 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
{
|
||||
ItemType selectedItem = this.listView.SelectedItem as ItemType;
|
||||
DragDropEffects allowedEffects = DragDropEffects.Move | DragDropEffects.Move | DragDropEffects.Link;
|
||||
if( DragDrop.DoDragDrop( this.listView, selectedItem, allowedEffects ) != DragDropEffects.None )
|
||||
if (DragDrop.DoDragDrop(this.listView, selectedItem, allowedEffects) != DragDropEffects.None)
|
||||
{
|
||||
// The item was dropped into a new location,
|
||||
// so make it the new selected item.
|
||||
@@ -666,18 +664,18 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
|
||||
void UpdateDragAdornerLocation()
|
||||
{
|
||||
if( this.dragAdorner != null )
|
||||
if (this.dragAdorner != null)
|
||||
{
|
||||
Point ptCursor = MouseUtilities.GetMousePosition( this.ListView );
|
||||
Point ptCursor = MouseUtilities.GetMousePosition(this.ListView);
|
||||
|
||||
double left = ptCursor.X - this.ptMouseDown.X;
|
||||
|
||||
// 4/13/2007 - Made the top offset relative to the item being dragged.
|
||||
ListViewItem itemBeingDragged = this.GetListViewItem( this.indexToSelect );
|
||||
Point itemLoc = itemBeingDragged.TranslatePoint( new Point( 0, 0 ), this.ListView );
|
||||
ListViewItem itemBeingDragged = this.GetListViewItem(this.indexToSelect);
|
||||
Point itemLoc = itemBeingDragged.TranslatePoint(new Point(0, 0), this.ListView);
|
||||
double top = itemLoc.Y + ptCursor.Y - this.ptMouseDown.Y;
|
||||
|
||||
this.dragAdorner.SetOffsets( left, top );
|
||||
this.dragAdorner.SetOffsets(left, top);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -706,17 +704,17 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
public static readonly DependencyProperty IsBeingDraggedProperty =
|
||||
DependencyProperty.RegisterAttached(
|
||||
"IsBeingDragged",
|
||||
typeof( bool ),
|
||||
typeof( ListViewItemDragState ),
|
||||
new UIPropertyMetadata( false ) );
|
||||
typeof(bool),
|
||||
typeof(ListViewItemDragState),
|
||||
new UIPropertyMetadata(false));
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the specified ListViewItem is being dragged, else false.
|
||||
/// </summary>
|
||||
/// <param name="item">The ListViewItem to check.</param>
|
||||
public static bool GetIsBeingDragged( ListViewItem item )
|
||||
public static bool GetIsBeingDragged(ListViewItem item)
|
||||
{
|
||||
return (bool)item.GetValue( IsBeingDraggedProperty );
|
||||
return (bool)item.GetValue(IsBeingDraggedProperty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -724,9 +722,9 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
/// </summary>
|
||||
/// <param name="item">The ListViewItem to set the property on.</param>
|
||||
/// <param name="value">Pass true if the element is being dragged, else false.</param>
|
||||
internal static void SetIsBeingDragged( ListViewItem item, bool value )
|
||||
internal static void SetIsBeingDragged(ListViewItem item, bool value)
|
||||
{
|
||||
item.SetValue( IsBeingDraggedProperty, value );
|
||||
item.SetValue(IsBeingDraggedProperty, value);
|
||||
}
|
||||
|
||||
#endregion // IsBeingDragged
|
||||
@@ -740,18 +738,18 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
public static readonly DependencyProperty IsUnderDragCursorProperty =
|
||||
DependencyProperty.RegisterAttached(
|
||||
"IsUnderDragCursor",
|
||||
typeof( bool ),
|
||||
typeof( ListViewItemDragState ),
|
||||
new UIPropertyMetadata( false ) );
|
||||
typeof(bool),
|
||||
typeof(ListViewItemDragState),
|
||||
new UIPropertyMetadata(false));
|
||||
|
||||
/// <summary>
|
||||
/// Returns true if the specified ListViewItem is currently underneath the cursor
|
||||
/// during a drag-drop operation, else false.
|
||||
/// </summary>
|
||||
/// <param name="item">The ListViewItem to check.</param>
|
||||
public static bool GetIsUnderDragCursor( ListViewItem item )
|
||||
public static bool GetIsUnderDragCursor(ListViewItem item)
|
||||
{
|
||||
return (bool)item.GetValue( IsUnderDragCursorProperty );
|
||||
return (bool)item.GetValue(IsUnderDragCursorProperty);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -759,9 +757,9 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
/// </summary>
|
||||
/// <param name="item">The ListViewItem to set the property on.</param>
|
||||
/// <param name="value">Pass true if the element is underneath the drag cursor, else false.</param>
|
||||
internal static void SetIsUnderDragCursor( ListViewItem item, bool value )
|
||||
internal static void SetIsUnderDragCursor(ListViewItem item, bool value)
|
||||
{
|
||||
item.SetValue( IsUnderDragCursorProperty, value );
|
||||
item.SetValue(IsUnderDragCursorProperty, value);
|
||||
}
|
||||
|
||||
#endregion // IsUnderDragCursor
|
||||
@@ -795,7 +793,7 @@ namespace WPF.JoshSmith.ServiceProviders.UI
|
||||
ItemType dataItem,
|
||||
int oldIndex,
|
||||
int newIndex,
|
||||
DragDropEffects allowedEffects )
|
||||
DragDropEffects allowedEffects)
|
||||
{
|
||||
this.itemsSource = itemsSource;
|
||||
this.dataItem = dataItem;
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
@@ -1,6 +1,4 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Text;
|
||||
using System.Runtime.InteropServices;
|
||||
using System.Windows;
|
||||
using System.Windows.Media;
|
||||
@@ -16,18 +14,18 @@ namespace WPF.JoshSmith.Controls.Utilities
|
||||
/// </remarks>
|
||||
public class MouseUtilities
|
||||
{
|
||||
[StructLayout( LayoutKind.Sequential )]
|
||||
[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
|
||||
@@ -35,15 +33,15 @@ namespace WPF.JoshSmith.Controls.Utilities
|
||||
/// 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 )
|
||||
public static Point GetMousePosition(Visual relativeTo)
|
||||
{
|
||||
Win32Point mouse = new Win32Point();
|
||||
GetCursorPos( ref mouse );
|
||||
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 ) );
|
||||
return relativeTo.PointFromScreen(new Point((double)mouse.X, (double)mouse.Y));
|
||||
|
||||
#region Commented Out
|
||||
//System.Windows.Interop.HwndSource presentationSource =
|
||||
|
||||
@@ -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
|
||||
{
|
||||
|
||||
@@ -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
61
ViewModel/AppData.cs
Normal 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));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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
137
ViewModel/IconInfo.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -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"
|
||||
////}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user