From 0e9e1f26116e92c68c049949b2b6f1cd8033c42f Mon Sep 17 00:00:00 2001 From: chylex <info@chylex.com> Date: Thu, 9 Apr 2015 20:33:09 +0200 Subject: [PATCH] Added Drag&Drop events --- BackupEssentials/MainWindow.xaml | 2 +- BackupEssentials/MainWindow.xaml.cs | 24 +++++++++++++++++++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/BackupEssentials/MainWindow.xaml b/BackupEssentials/MainWindow.xaml index e4fc60f..e00e005 100644 --- a/BackupEssentials/MainWindow.xaml +++ b/BackupEssentials/MainWindow.xaml @@ -7,7 +7,7 @@ xmlns:custom="clr-namespace:BackupEssentials.Controls" xmlns:Themes="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero" mc:Ignorable="d" x:Class="BackupEssentials.MainWindow" - Title="Backup" Height="600" Width="800" WindowStartupLocation="CenterScreen" WindowStyle="None" ResizeMode="CanResizeWithGrip" Background="#FF000000" AllowsTransparency="True" AllowDrop="True" MinWidth="800" MinHeight="600"> + Title="Backup" Height="600" Width="800" WindowStartupLocation="CenterScreen" WindowStyle="None" ResizeMode="CanResizeWithGrip" Background="#FF000000" AllowsTransparency="True" AllowDrop="True" MinWidth="800" MinHeight="600" DragEnter="OnDragEnter" DragLeave="OnDragLeave" Drop="OnDragDrop"> <Window.Resources> <Style TargetType="ResizeGrip"> <Setter Property="Margin" Value="2"/> diff --git a/BackupEssentials/MainWindow.xaml.cs b/BackupEssentials/MainWindow.xaml.cs index 1bbad02..8317ebc 100644 --- a/BackupEssentials/MainWindow.xaml.cs +++ b/BackupEssentials/MainWindow.xaml.cs @@ -17,6 +17,8 @@ namespace BackupEssentials{ private new Rect RestoreBounds = new Rect(); private bool IsMaximized = false; + private string[] DropData = null; + public MainWindow(){ InitializeComponent(); Instance = this; @@ -91,6 +93,24 @@ namespace BackupEssentials{ ShowPage(GetType().Assembly.GetType("BackupEssentials."+btn.ClickPage,false)); } + private void OnDragEnter(object sender, System.Windows.DragEventArgs e){ + if (DropData == null && e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop))DropData = e.Data.GetData(System.Windows.DataFormats.FileDrop) as string[]; + else e.Effects = System.Windows.DragDropEffects.None; + + e.Handled = true; + } + + private void OnDragLeave(object sender, System.Windows.DragEventArgs e){ + DropData = null; + } + + private void OnDragDrop(object sender, System.Windows.DragEventArgs e){ + if (DropData != null){ + // TODO display backup page + DropData = null; + } + } + public void ShowPage(Type pageType){ ShowPage(pageType,null); } @@ -104,7 +124,9 @@ namespace BackupEssentials{ if (!page.AllowDrop){ page.AllowDrop = true; - // TODO handle events + page.DragEnter += new System.Windows.DragEventHandler(OnDragEnter); + page.DragLeave += new System.Windows.DragEventHandler(OnDragLeave); + page.Drop += new System.Windows.DragEventHandler(OnDragDrop); } } }