WidthConvert.cs 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Diagnostics;
  4. using System.Globalization;
  5. using System.Linq;
  6. using System.Text;
  7. using System.Threading.Tasks;
  8. using System.Windows;
  9. using System.Windows.Controls;
  10. using System.Windows.Data;
  11. namespace PDF_Master.DataConvert
  12. {
  13. public class WidthConvert : IValueConverter
  14. {
  15. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  16. {
  17. if (value == null)
  18. {
  19. return 0;
  20. }
  21. else
  22. {
  23. if (value is double)
  24. {
  25. double width = (double)value;
  26. width = width - SystemParameters.VerticalScrollBarWidth-8;
  27. return Math.Max(0, width);
  28. }
  29. else
  30. {
  31. return 0;
  32. }
  33. }
  34. }
  35. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  36. {
  37. throw new NotImplementedException();
  38. }
  39. }
  40. public class SearchWidthConvert : IValueConverter
  41. {
  42. public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
  43. {
  44. if (value == null)
  45. {
  46. return 0;
  47. }
  48. else
  49. {
  50. if (value is double)
  51. {
  52. double width = (double)value;
  53. width = width - SystemParameters.VerticalScrollBarWidth-20;
  54. return Math.Max(0, width);
  55. }
  56. else
  57. {
  58. return 0;
  59. }
  60. }
  61. }
  62. public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
  63. {
  64. throw new NotImplementedException();
  65. }
  66. }
  67. public class WidthMultiConvert : IMultiValueConverter
  68. {
  69. public object Convert(object[] values, Type targetType, object parameter, CultureInfo culture)
  70. {
  71. if (values == null || values.Length==0)
  72. {
  73. return 0;
  74. }
  75. else
  76. {
  77. if (values[0] is double)
  78. {
  79. double width = (double)values[0];
  80. width = width - SystemParameters.VerticalScrollBarWidth - 8;
  81. return Math.Max(0, width);
  82. }
  83. else
  84. {
  85. return 0;
  86. }
  87. }
  88. }
  89. public object[] ConvertBack(object value, Type[] targetTypes, object parameter, CultureInfo culture)
  90. {
  91. throw new NotImplementedException();
  92. }
  93. }
  94. }