HomeContent.xaml.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. using PDF_Master.CustomControl;
  2. using PDF_Master.Helper;
  3. using PDF_Master.ViewModels;
  4. using System;
  5. using System.Collections.Generic;
  6. using System.Collections.ObjectModel;
  7. using System.Linq;
  8. using System.Text;
  9. using System.Threading.Tasks;
  10. using System.Windows;
  11. using System.Windows.Controls;
  12. using System.Windows.Data;
  13. using System.Windows.Documents;
  14. using System.Windows.Input;
  15. using System.Windows.Media;
  16. using System.Windows.Media.Imaging;
  17. using System.Windows.Navigation;
  18. using System.Windows.Shapes;
  19. namespace PDF_Master.Views
  20. {
  21. public class PromotionBanner
  22. {
  23. public string ImagePath { get; set; }
  24. public string Content { get; set; }
  25. public string Uri { get; set; }
  26. public PromotionBanner(string ImagePath, string Content, string uri)
  27. {
  28. this.ImagePath = ImagePath;
  29. this.Content = Content;
  30. this.Uri = uri;
  31. }
  32. }
  33. /// <summary>
  34. /// HomeContent.xaml 的交互逻辑
  35. /// </summary>
  36. public partial class HomeContent : UserControl
  37. {
  38. private HomeContentViewModel viewModel;
  39. private bool IsContextMenuOpen = false;
  40. public HomeContent()
  41. {
  42. InitializeComponent();
  43. BtnGuid.IsChecked = true;
  44. viewModel = this.DataContext as HomeContentViewModel;
  45. }
  46. private void ToggleBtnSelect_Click(object sender, RoutedEventArgs e)
  47. {
  48. BtnGuid.IsChecked = false;
  49. BtnTool.IsChecked = false;
  50. BtnCloud.IsChecked = false;
  51. var btn = sender as CustomIconToggleBtn;
  52. if (btn != null)
  53. {
  54. btn.IsChecked = true;
  55. }
  56. }
  57. private void BtnCreatPDF_Initialized(object sender, EventArgs e)
  58. {
  59. var btn = sender as Button;
  60. if (btn != null)
  61. {
  62. btn.ContextMenu = null;
  63. }
  64. }
  65. private void BtnExpand_Click(object sender, RoutedEventArgs e)
  66. {
  67. ContextCreatePDF.PlacementTarget = BtnCreatPDF;
  68. ContextCreatePDF.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
  69. IsContextMenuOpen = !IsContextMenuOpen;
  70. ContextCreatePDF.IsOpen = IsContextMenuOpen;
  71. }
  72. private void ContextCreatePDF_Closed(object sender, RoutedEventArgs e)
  73. {
  74. var visual = VisualTreeHelper.HitTest(BtnExpand, Mouse.GetPosition(BtnExpand));
  75. if (visual == null)
  76. {
  77. //点击其他地方引起的下拉框收取,猜需要更改按钮状态,
  78. //如果是点击按钮造成的下拉框收起,则不需要更改按钮状态(如果改了,会出现每次缓慢点击按钮都展开下拉框的现象)
  79. IsContextMenuOpen = false;
  80. }
  81. }
  82. private void UserControl_DragEnter(object sender, DragEventArgs e)
  83. {
  84. DragDropHelper.DragEnter(this, e);
  85. }
  86. private void UserControl_DragOver(object sender, DragEventArgs e)
  87. {
  88. DragDropHelper.DragOver(this, e);
  89. }
  90. private void UserControl_DragLeave(object sender, DragEventArgs e)
  91. {
  92. DragDropHelper.DragLeave();
  93. }
  94. private void UserControl_Drop(object sender, DragEventArgs e)
  95. {
  96. try
  97. {
  98. DragDropHelper.Drop(this, e);
  99. string[] file = (string[])e.Data.GetData(DataFormats.FileDrop);
  100. if (file.Length > 0)
  101. {
  102. //判断是否为Home页面
  103. if (viewModel.currentViewName == "Guid")
  104. {
  105. (this.DataContext as HomeContentViewModel).AddFileFromDrag(file.ToList());
  106. }
  107. }
  108. }
  109. catch { }
  110. }
  111. }
  112. }