QuickToolsContent.xaml.cs 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125
  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 PDFSettings;
  7. using System.Collections.Generic;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Media;
  11. namespace PDF_Office.Views.HomePanel.PDFTools
  12. {
  13. /// <summary>
  14. /// HomeToolIControl.xaml 的交互逻辑0
  15. ///
  16. /// </summary>
  17. public partial class QuickToolsContent : UserControl
  18. {
  19. PDFToolsHelper PDFtools;
  20. public QuickToolsContent()
  21. {
  22. InitializeComponent();
  23. PDFtools = PDFToolsHelper.GetInstance();
  24. ListBoxToolBars.ItemsSource = PDFtools.QuickTools;
  25. }
  26. private void BtnMore_Click(object sender, RoutedEventArgs e)
  27. {
  28. }
  29. private void BtnExptend_Click(object sender, RoutedEventArgs e)
  30. {
  31. UpdateExptendUI();
  32. }
  33. private void UpdateExptendUI()
  34. {
  35. if ((bool)BtnExptend.IsChecked)
  36. {
  37. GridAllTools.Height = 270;
  38. }
  39. else
  40. {
  41. GridAllTools.Height = 174;
  42. }
  43. foreach (var item in PDFtools.QuickTools)
  44. {
  45. item.IsShowConciseContent = !(bool)BtnExptend.IsChecked;
  46. }
  47. }
  48. /// <summary>
  49. /// 编辑工具
  50. /// </summary>
  51. private void BtnTools_Click(object sender, RoutedEventArgs e)
  52. {
  53. }
  54. private void GridAllTools_SizeChanged(object sender, SizeChangedEventArgs e)
  55. {
  56. ListBoxToolBarsWidthChanged();
  57. }
  58. private void ListBoxToolBarsWidthChanged()
  59. {
  60. double containerWidth = ListBoxToolBars.ActualWidth - 20;
  61. int widthItem = (int)containerWidth / 5;
  62. double margin = widthItem / 3;
  63. int i = 0;
  64. foreach (var item in ListBoxToolBars.Items)
  65. {
  66. i++;
  67. var listBoxItem = ListBoxToolBars.ItemContainerGenerator.ContainerFromItem(item) as ListBoxItem;
  68. if (listBoxItem != null)
  69. {
  70. if (i % 4 != 0)
  71. {
  72. listBoxItem.Margin = new Thickness(0, 0, margin, 0);
  73. }
  74. else
  75. {
  76. listBoxItem.Margin = new Thickness(0, 0, 0, 0);
  77. }
  78. listBoxItem.Width = widthItem;
  79. }
  80. }
  81. }
  82. private void ListBoxShortCuts_SizeChanged(object sender, SizeChangedEventArgs e)
  83. {
  84. }
  85. private void QuickTools_Click(object sender, System.Windows.Input.MouseButtonEventArgs e)
  86. {
  87. var toolItem = (sender as FrameworkElement).DataContext as ToolItem;
  88. var veiwModel = this.DataContext as HomeGuidContentViewModel;
  89. if (veiwModel != null && toolItem != null)
  90. {
  91. veiwModel.QuickToolsCommand.Execute(toolItem);
  92. }
  93. }
  94. private void UserControl_Loaded(object sender, RoutedEventArgs e)
  95. {
  96. if(ListBoxToolBars.Items != null)
  97. {
  98. UpdateExptendUI();
  99. ListBoxToolBars.Items.Refresh();
  100. ListBoxToolBarsWidthChanged();
  101. }
  102. }
  103. }
  104. }