DynamicGridCodeColumn.cs 2.2 KB

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