HomeToolIControl.xaml.cs 4.1 KB

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