using ComPDFKit.PDFDocument; using PDF_Master.Helper; using PDF_Master.Model; using PDF_Master.Properties; using PDF_Master.ViewModels.HomePanel.PDFTools; using System; using System.Diagnostics; using System.IO; using System.Windows; using System.Windows.Controls; using System.Windows.Interop; namespace PDF_Master.Views.HomePanel.PDFTools { /// /// Interaction logic for HomeFilesContent /// public partial class HomeFilesContent : UserControl { private HomeFilesContentViewModel viewModel; private IDropTargetHelper dropHelper; public HomeFilesContent() { InitializeComponent(); viewModel= DataContext as HomeFilesContentViewModel; } private void StackPanel_SizeChanged(object sender, System.Windows.SizeChangedEventArgs e) { if (Gridroot.ActualWidth<638) { OpenFileStackPanel.Margin=new System.Windows.Thickness(0,0,0,0); viewModel.CreatGridRowIndex = 1; viewModel.CreatGridColumnIndex = 0; } else { OpenFileStackPanel.Margin = new System.Windows.Thickness(0, 0, 20, 0); viewModel.CreatGridRowIndex = 0; viewModel.CreatGridColumnIndex = 1; } } private void Grid_Drop(object sender, DragEventArgs e) { DropColorBorder.Visibility = Visibility.Hidden; NormalColorBorder.Visibility = Visibility.Visible; try { Point iconPoint = e.GetPosition(this); dropHelper?.Drop((System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects); } catch { } string dropFile = "Drop"; if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop)) { //BtnBlank.IsEnabled = true; int count = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).Length; for (int i = 0; i < count; i++) { dropFile = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).GetValue(i).ToString(); } } } private void MainPage_DragEnter(object sender, DragEventArgs e) { DropColorBorder.Visibility = Visibility.Visible; NormalColorBorder.Visibility = Visibility.Hidden; //BtnBlank.IsEnabled = false; //页面编辑和缩略图 if ((e.OriginalSource as Image) != null) return; try { if (dropHelper == null) { dropHelper = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("4657278A-411B-11D2-839A-00C04FD918D0"))) as IDropTargetHelper; } Point iconPoint = e.GetPosition(this); dropHelper?.DragEnter(new WindowInteropHelper(Window.GetWindow(this)).Handle, (System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects); } catch { } } private void MainPage_DragOver(object sender, DragEventArgs e) { if ((e.OriginalSource as Image) != null) return; try { Point iconPoint = e.GetPosition(this); dropHelper?.DragOver(ref iconPoint, e.Effects); } catch { } } private void MainPage_DragLeave(object sender, DragEventArgs e) { DropColorBorder.Visibility = Visibility.Hidden; NormalColorBorder.Visibility = Visibility.Visible; // BtnBlank.IsEnabled = true; if ((e.OriginalSource as Image) != null) return; try { dropHelper?.DragLeave(); } catch { } } private void Grid_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e) { DropColorBorder.Visibility = Visibility.Visible; NormalColorBorder.Visibility = Visibility.Hidden; } private void Grid_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e) { DropColorBorder.Visibility = Visibility.Hidden; NormalColorBorder.Visibility = Visibility.Visible; } } }