DynamicGridCheckBoxColumn.cs 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Windows;
  4. using System.Windows.Controls;
  5. using System.Windows.Controls.Primitives;
  6. using System.Windows.Data;
  7. using System.Windows.Media.Imaging;
  8. using InABox.Core;
  9. using InABox.WPF;
  10. using Syncfusion.UI.Xaml.Grid;
  11. namespace InABox.DynamicGrid;
  12. public class DynamicGridCheckBoxColumn<TEntity> : DynamicGridEditorColumn<TEntity,CheckBoxEditor,GridTemplateColumn>
  13. where TEntity : BaseObject
  14. {
  15. private readonly BitmapSource tick = Wpf.Resources.tick.AsBitmapImage();
  16. protected override void Configure(GridTemplateColumn column, CheckBoxEditor editor)
  17. {
  18. column.CellTemplate = TemplateGenerator.CreateDataTemplate
  19. (
  20. () =>
  21. {
  22. var result = new Image() { Source = tick, Margin = new Thickness(2) };
  23. var binding = new Binding() { Path = new PropertyPath(MappingName), Converter = new BooleanToVisibilityConverter() };
  24. result.SetBinding(UIElement.VisibilityProperty, binding);
  25. return result;
  26. }
  27. );
  28. column.EditTemplate = TemplateGenerator.CreateDataTemplate
  29. (
  30. () =>
  31. {
  32. var result = new CheckBox() { IsThreeState = false };
  33. var binding = new Binding() { Path = new PropertyPath(MappingName) };
  34. result.SetBinding(ToggleButton.IsCheckedProperty, binding);
  35. result.HorizontalAlignment = HorizontalAlignment.Center;
  36. result.VerticalAlignment = VerticalAlignment.Center;
  37. return result;
  38. }
  39. );
  40. column.SetCellBoundValue = false;
  41. }
  42. public override bool Filtered => false;
  43. public override bool VariableWidth => false;
  44. public DynamicGridCheckBoxColumn(DynamicGridColumn definition) : base(definition)
  45. {
  46. }
  47. }