QuickToolsContent.xaml.cs 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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. PDFToolsHelper PDFtools;
  19. public QuickToolsContent()
  20. {
  21. InitializeComponent();
  22. PDFtools = new PDFToolsHelper();
  23. ListBoxToolBars.ItemsSource = PDFtools.QuickTools;
  24. }
  25. private void BtnMore_Click(object sender, RoutedEventArgs e)
  26. {
  27. if (GridAllTools.Height != 270)
  28. {
  29. GridAllTools.Height = 270;
  30. ShowToolsUI(false);
  31. }
  32. else
  33. {
  34. GridAllTools.Height = 184;
  35. ShowToolsUI(true);
  36. }
  37. }
  38. /// <summary>
  39. /// 扩展收缩UI
  40. /// </summary>
  41. /// <param name="IsShowConciseContent">是否收缩</param>
  42. private void ShowToolsUI(bool IsShowConciseContent)
  43. {
  44. foreach (var item in ListBoxToolBars.Items)
  45. {
  46. var listBoxItem = ListBoxToolBars.ItemContainerGenerator.ContainerFromItem(item) as ListBoxItem;
  47. if (listBoxItem != null)
  48. {
  49. var viewItem = listBoxItem.ContentTemplate;
  50. var myContentPresenter = CommonHelper.FindVisualChild<ContentPresenter>(listBoxItem);
  51. var obj = viewItem.FindName("data", myContentPresenter);
  52. var checkNum = obj as PDFToolItem;
  53. if (checkNum != null)
  54. {
  55. checkNum.IsShowConciseContent = IsShowConciseContent;
  56. }
  57. }
  58. }
  59. }
  60. /// <summary>
  61. /// 编辑工具
  62. /// </summary>
  63. private void BtnTools_Click(object sender, RoutedEventArgs e)
  64. {
  65. }
  66. private void GridAllTools_SizeChanged(object sender, SizeChangedEventArgs e)
  67. {
  68. ListBoxToolBarsWidthChanged();
  69. }
  70. private void ListBoxToolBarsWidthChanged()
  71. {
  72. double containerWidth = ListBoxToolBars.ActualWidth - 20;
  73. int widthItem = (int)containerWidth / 5;
  74. double margin = widthItem / 3;
  75. int i = 0;
  76. foreach (var item in ListBoxToolBars.Items)
  77. {
  78. i++;
  79. var listBoxItem = ListBoxToolBars.ItemContainerGenerator.ContainerFromItem(item) as ListBoxItem;
  80. if (listBoxItem != null)
  81. {
  82. if (i % 4 != 0)
  83. {
  84. listBoxItem.Margin = new Thickness(0, 0, margin, 20);
  85. }
  86. else
  87. {
  88. listBoxItem.Margin = new Thickness(0, 0, 0, 20);
  89. }
  90. listBoxItem.Width = widthItem;
  91. }
  92. }
  93. }
  94. private void ListBoxShortCuts_SizeChanged(object sender, SizeChangedEventArgs e)
  95. {
  96. }
  97. private void QuickTools_Click(object sender, System.Windows.Input.MouseButtonEventArgs e)
  98. {
  99. var toolItem = (sender as FrameworkElement).DataContext as ToolItem;
  100. var veiwModel = this.DataContext as HomeGuidContentViewModel;
  101. if (veiwModel != null && toolItem != null)
  102. {
  103. veiwModel.QuickToolsCommand.Execute(toolItem);
  104. }
  105. }
  106. }
  107. }