HomeContent.xaml.cs 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. using PDF_Office.CustomControl;
  2. using PDF_Office.Helper;
  3. using PDF_Office.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_Office.Views
  20. {
  21. public class PromotionBanner
  22. {
  23. public string ImagePath { get; set; }
  24. public string Content { get; set; }
  25. public PromotionBanner(string ImagePath,string Content)
  26. {
  27. this.ImagePath = ImagePath;
  28. this.Content = Content;
  29. }
  30. }
  31. /// <summary>
  32. /// HomeContent.xaml 的交互逻辑
  33. /// </summary>
  34. public partial class HomeContent : UserControl
  35. {
  36. private bool IsContextMenuOpen = false;
  37. public HomeContent()
  38. {
  39. InitializeComponent();
  40. BtnGuid.IsChecked = true;
  41. }
  42. private void ToggleBtnSelect_Click(object sender, RoutedEventArgs e)
  43. {
  44. BtnGuid.IsChecked = false;
  45. BtnTool.IsChecked = false;
  46. BtnCloud.IsChecked = false;
  47. var btn = sender as CustomIconToggleBtn;
  48. if(btn != null )
  49. {
  50. btn.IsChecked = true;
  51. }
  52. }
  53. private void BtnCreatPDF_Initialized(object sender, EventArgs e)
  54. {
  55. var btn = sender as Button;
  56. if(btn!=null)
  57. {
  58. btn.ContextMenu = null;
  59. }
  60. }
  61. private void BtnExpand_Click(object sender, RoutedEventArgs e)
  62. {
  63. ContextCreatePDF.PlacementTarget = BtnCreatPDF;
  64. ContextCreatePDF.Placement = System.Windows.Controls.Primitives.PlacementMode.Bottom;
  65. IsContextMenuOpen = !IsContextMenuOpen;
  66. ContextCreatePDF.IsOpen = IsContextMenuOpen;
  67. }
  68. private void ContextCreatePDF_Closed(object sender, RoutedEventArgs e)
  69. {
  70. var visual = VisualTreeHelper.HitTest(BtnExpand, Mouse.GetPosition(BtnExpand));
  71. if (visual == null)
  72. {
  73. //点击其他地方引起的下拉框收取,猜需要更改按钮状态,
  74. //如果是点击按钮造成的下拉框收起,则不需要更改按钮状态(如果改了,会出现每次缓慢点击按钮都展开下拉框的现象)
  75. IsContextMenuOpen = false;
  76. }
  77. }
  78. private void UserControl_DragEnter(object sender, DragEventArgs e)
  79. {
  80. DragDropHelper.DragEnter(this,e);
  81. }
  82. private void UserControl_DragOver(object sender, DragEventArgs e)
  83. {
  84. DragDropHelper.DragOver(this, e);
  85. }
  86. private void UserControl_DragLeave(object sender, DragEventArgs e)
  87. {
  88. DragDropHelper.DragLeave();
  89. }
  90. private void UserControl_Drop(object sender, DragEventArgs e)
  91. {
  92. try
  93. {
  94. DragDropHelper.Drop(this, e);
  95. string[] file = (string[])e.Data.GetData(DataFormats.FileDrop);
  96. if(file.Length>0)
  97. {
  98. (this.DataContext as HomeContentViewModel).AddFileFromDrag(file.ToList());
  99. }
  100. }
  101. catch { }
  102. }
  103. }
  104. }