QuickToolsContent.xaml.cs 4.2 KB

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