QuickToolsContent.cs 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. using PDF_Office.CustomControl;
  2. using PDF_Office.Helper;
  3. using PDF_Office.ViewModels.HomePanel;
  4. using PDF_Office.Views.HomePanel.PDFTools;
  5. using System.Collections.Generic;
  6. using System.Windows;
  7. using System.Windows.Controls;
  8. using System.Windows.Media;
  9. namespace PDF_Office.Views.HomePanel.PDFTools
  10. {
  11. /// <summary>
  12. /// HomeToolIControl.xaml 的交互逻辑0
  13. ///
  14. /// </summary>
  15. public partial class QuickToolsContent : UserControl
  16. {
  17. private List<QuickToolItem> allToolbars = null;
  18. public QuickToolsContent()
  19. {
  20. InitializeComponent();
  21. allToolbars = new List<QuickToolItem>();
  22. string path = @"pack://application:,,,/Resources/PromotionIcon/Windows.png";
  23. List<string> all = new List<string>() { "PDF转Word", "PDF转Excel", "PDF转PPT", "转档PDF", "OCR", "拆分",
  24. "提取","合并","压缩","图片转PDF","安全", "水印", "页眉页脚","贝茨Bates码","批量处理","打印", "背景","插入","文件对比"};
  25. for (int i = 0; i < 8; i++)
  26. {
  27. QuickToolItem aToolModule = new QuickToolItem();
  28. aToolModule.Id = i + 1;
  29. aToolModule.Name = all[i];
  30. aToolModule.Image = path;
  31. aToolModule.NameInfo = "Batch convert, compress, secure, watermark PDFs.";
  32. allToolbars.Add(aToolModule);
  33. }
  34. ListBoxToolBars.ItemsSource = allToolbars;
  35. }
  36. private void BtnMore_Click(object sender, RoutedEventArgs e)
  37. {
  38. if (GridAllTools.Height != 270)
  39. {
  40. GridAllTools.Height = 270;
  41. ShowToolsUI(false);
  42. }
  43. else
  44. {
  45. GridAllTools.Height = 184;
  46. ShowToolsUI(true);
  47. }
  48. }
  49. /// <summary>
  50. /// 扩展收缩UI
  51. /// </summary>
  52. /// <param name="IsShowConciseContent">是否收缩</param>
  53. private void ShowToolsUI(bool IsShowConciseContent)
  54. {
  55. foreach (var item in ListBoxToolBars.Items)
  56. {
  57. var listBoxItem = ListBoxToolBars.ItemContainerGenerator.ContainerFromItem(item) as ListBoxItem;
  58. if (listBoxItem != null)
  59. {
  60. var viewItem = listBoxItem.ContentTemplate;
  61. var myContentPresenter = CommonHelper.FindVisualChild<ContentPresenter>(listBoxItem);
  62. var obj = viewItem.FindName("data", myContentPresenter);
  63. var checkNum = obj as HomeToolItem;
  64. if (checkNum != null)
  65. {
  66. checkNum.IsShowConciseContent = IsShowConciseContent;
  67. }
  68. }
  69. }
  70. }
  71. /// <summary>
  72. /// 编辑工具
  73. /// </summary>
  74. private void BtnTools_Click(object sender, RoutedEventArgs e)
  75. {
  76. }
  77. private void GridAllTools_SizeChanged(object sender, SizeChangedEventArgs e)
  78. {
  79. ListBoxToolBarsWidthChanged();
  80. }
  81. private void ListBoxToolBarsWidthChanged()
  82. {
  83. double containerWidth = ListBoxToolBars.ActualWidth - 20;
  84. int widthItem = (int)containerWidth / 5;
  85. double margin = widthItem / 3;
  86. int i = 0;
  87. foreach (var item in ListBoxToolBars.Items)
  88. {
  89. i++;
  90. var listBoxItem = ListBoxToolBars.ItemContainerGenerator.ContainerFromItem(item) as ListBoxItem;
  91. if (listBoxItem != null)
  92. {
  93. if (i % 4 != 0)
  94. {
  95. listBoxItem.Margin = new Thickness(0, 0, margin, 20);
  96. }
  97. else
  98. {
  99. listBoxItem.Margin = new Thickness(0, 0, 0, 20);
  100. }
  101. listBoxItem.Width = widthItem;
  102. }
  103. }
  104. }
  105. private void ListBoxShortCuts_SizeChanged(object sender, SizeChangedEventArgs e)
  106. {
  107. }
  108. }
  109. }