HomeContent.xaml.cs 3.6 KB

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