HomeFilesContent.xaml.cs 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  1. using ComPDFKit.PDFDocument;
  2. using PDF_Master.Helper;
  3. using PDF_Master.Model;
  4. using PDF_Master.Properties;
  5. using PDF_Master.ViewModels.HomePanel.PDFTools;
  6. using System;
  7. using System.Diagnostics;
  8. using System.IO;
  9. using System.Windows;
  10. using System.Windows.Controls;
  11. using System.Windows.Interop;
  12. namespace PDF_Master.Views.HomePanel.PDFTools
  13. {
  14. /// <summary>
  15. /// Interaction logic for HomeFilesContent
  16. /// </summary>
  17. public partial class HomeFilesContent : UserControl
  18. {
  19. private HomeFilesContentViewModel viewModel;
  20. private IDropTargetHelper dropHelper;
  21. public HomeFilesContent()
  22. {
  23. InitializeComponent();
  24. viewModel= DataContext as HomeFilesContentViewModel;
  25. }
  26. private void StackPanel_SizeChanged(object sender, System.Windows.SizeChangedEventArgs e)
  27. {
  28. if (Gridroot.ActualWidth<638)
  29. {
  30. OpenFileStackPanel.Margin=new System.Windows.Thickness(0,0,0,0);
  31. viewModel.CreatGridRowIndex = 1;
  32. viewModel.CreatGridColumnIndex = 0;
  33. }
  34. else
  35. {
  36. OpenFileStackPanel.Margin = new System.Windows.Thickness(0, 0, 20, 0);
  37. viewModel.CreatGridRowIndex = 0;
  38. viewModel.CreatGridColumnIndex = 1;
  39. }
  40. }
  41. private void Grid_Drop(object sender, DragEventArgs e)
  42. {
  43. DropColorBorder.Visibility = Visibility.Hidden;
  44. NormalColorBorder.Visibility = Visibility.Visible;
  45. try
  46. {
  47. Point iconPoint = e.GetPosition(this);
  48. dropHelper?.Drop((System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects);
  49. }
  50. catch
  51. {
  52. }
  53. string dropFile = "Drop";
  54. if (e.Data.GetDataPresent(System.Windows.DataFormats.FileDrop))
  55. {
  56. //BtnBlank.IsEnabled = true;
  57. int count = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).Length;
  58. for (int i = 0; i < count; i++)
  59. {
  60. dropFile = ((System.Array)e.Data.GetData(System.Windows.DataFormats.FileDrop)).GetValue(i).ToString();
  61. }
  62. }
  63. }
  64. private void MainPage_DragEnter(object sender, DragEventArgs e)
  65. {
  66. DropColorBorder.Visibility = Visibility.Visible;
  67. NormalColorBorder.Visibility = Visibility.Hidden;
  68. //BtnBlank.IsEnabled = false;
  69. //页面编辑和缩略图
  70. if ((e.OriginalSource as Image) != null)
  71. return;
  72. try
  73. {
  74. if (dropHelper == null)
  75. {
  76. dropHelper = Activator.CreateInstance(Type.GetTypeFromCLSID(new Guid("4657278A-411B-11D2-839A-00C04FD918D0"))) as IDropTargetHelper;
  77. }
  78. Point iconPoint = e.GetPosition(this);
  79. dropHelper?.DragEnter(new WindowInteropHelper(Window.GetWindow(this)).Handle, (System.Runtime.InteropServices.ComTypes.IDataObject)e.Data, ref iconPoint, e.Effects);
  80. }
  81. catch
  82. {
  83. }
  84. }
  85. private void MainPage_DragOver(object sender, DragEventArgs e)
  86. {
  87. if ((e.OriginalSource as Image) != null)
  88. return;
  89. try
  90. {
  91. Point iconPoint = e.GetPosition(this);
  92. dropHelper?.DragOver(ref iconPoint, e.Effects);
  93. }
  94. catch
  95. {
  96. }
  97. }
  98. private void MainPage_DragLeave(object sender, DragEventArgs e)
  99. {
  100. DropColorBorder.Visibility = Visibility.Hidden;
  101. NormalColorBorder.Visibility = Visibility.Visible;
  102. // BtnBlank.IsEnabled = true;
  103. if ((e.OriginalSource as Image) != null)
  104. return;
  105. try
  106. {
  107. dropHelper?.DragLeave();
  108. }
  109. catch
  110. {
  111. }
  112. }
  113. private void Grid_MouseEnter(object sender, System.Windows.Input.MouseEventArgs e)
  114. {
  115. DropColorBorder.Visibility = Visibility.Visible;
  116. NormalColorBorder.Visibility = Visibility.Hidden;
  117. }
  118. private void Grid_MouseLeave(object sender, System.Windows.Input.MouseEventArgs e)
  119. {
  120. DropColorBorder.Visibility = Visibility.Hidden;
  121. NormalColorBorder.Visibility = Visibility.Visible;
  122. }
  123. }
  124. }