DynamicGridUniqueCodeColumn.cs 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. using System.Windows;
  2. using System.Windows.Controls;
  3. using System.Windows.Data;
  4. using InABox.Core;
  5. using InABox.WPF;
  6. using Syncfusion.UI.Xaml.Grid;
  7. namespace InABox.DynamicGrid;
  8. public class DynamicGridUniqueCodeColumn<TEntity> : DynamicGridEditorColumn<TEntity,UniqueCodeEditor,GridTemplateColumn> where TEntity : BaseObject
  9. {
  10. protected override void Configure(GridTemplateColumn column, UniqueCodeEditor editor)
  11. {
  12. column.CellTemplate = TemplateGenerator.CreateDataTemplate
  13. (
  14. () =>
  15. {
  16. var result = new Label();
  17. result.HorizontalContentAlignment = Column.TextAlignment == TextAlignment.Left
  18. ? HorizontalAlignment.Left
  19. : Column.TextAlignment == TextAlignment.Center
  20. ? HorizontalAlignment.Center
  21. : HorizontalAlignment.Right;
  22. var binding = new Binding()
  23. {
  24. Path = new PropertyPath(MappingName),
  25. };
  26. result.SetBinding(Label.ContentProperty, binding);
  27. return result;
  28. }
  29. );
  30. column.EditTemplate = TemplateGenerator.CreateDataTemplate
  31. (
  32. () =>
  33. {
  34. var textbox = new TextBox();
  35. textbox.CharacterCasing = CharacterCasing.Upper;
  36. textbox.TextAlignment = Column.TextAlignment;
  37. textbox.SetBinding(TextBox.TextProperty, new Binding()
  38. {
  39. Path = new PropertyPath(MappingName)
  40. });
  41. textbox.SetValue(Grid.ColumnSpanProperty, 2);
  42. textbox.Padding = new Thickness(2, 0, 0, 0);
  43. textbox.VerticalContentAlignment = VerticalAlignment.Center;
  44. textbox.PreviewTextInput += (sender, args) => textbox.Tag = true;
  45. textbox.TextChanged += (sender, args) =>
  46. {
  47. if (Equals(textbox.Tag, false))
  48. {
  49. textbox.SelectAll();
  50. textbox.Tag = true;
  51. }
  52. };
  53. textbox.SetValue(FocusManagerHelper.FocusedElementProperty, true);
  54. return textbox;
  55. }
  56. );
  57. }
  58. public DynamicGridUniqueCodeColumn(DynamicGridColumn definition) : base(definition)
  59. {
  60. }
  61. }