GridUtils.cs 1.2 KB

12345678910111213141516171819202122232425262728293031
  1. using System.Drawing;
  2. using System.Windows;
  3. using InABox.WPF;
  4. using Syncfusion.Windows.Controls.Cells;
  5. using Syncfusion.Windows.Controls.Grid;
  6. using Image = System.Windows.Controls.Image;
  7. namespace PRSDesktop.Utils
  8. {
  9. internal class GridUtils
  10. {
  11. public static void SetButtonImage(GridStyleInfo style, Bitmap bitmap, GridModel model, int column)
  12. {
  13. if (bitmap == null)
  14. return;
  15. style.Image = new Image { Source = bitmap.AsBitmapImage() };
  16. style.ImageContentStretch = ImageContentStretch.Absolute;
  17. var MaxHeight = model.RowHeights.DefaultLineSize;
  18. var MaxWidth = model.ColumnWidths[column];
  19. var size = (MaxHeight > MaxWidth ? MaxWidth : MaxHeight) * 0.66;
  20. style.ImageHeight = new GridLength(size);
  21. style.ImageWidth = new GridLength(size);
  22. var VMargin = (MaxHeight - size) / 40;
  23. var HMargin = (MaxWidth - size) / 2;
  24. style.ImageMargins = new CellMarginsInfo(HMargin, VMargin, MaxWidth - HMargin, MaxHeight - VMargin);
  25. style.ReadOnly = true;
  26. //style.HorizontalAlignment = HorizontalAlignment.Center;
  27. //style.VerticalAlignment = VerticalAlignment.Center;
  28. }
  29. }
  30. }