MasterDetailGridPage.cs 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. using System.Collections.Generic;
  2. using InABox.Core;
  3. using InABox.DynamicGrid;
  4. namespace InABox.Wpf;
  5. public abstract class MasterDetailGridPage<TMaster, TGrid, TDetail> : MasterDetailPage<TMaster>
  6. where TGrid : DynamicGrid<TDetail>, IDataModelSource, IMasterDetailControl<TMaster,TDetail>, new()
  7. where TDetail : BaseObject, new()
  8. {
  9. public TGrid? Grid { get; set; }
  10. public MasterDetailGridPage(DynamicTabItem tab) : base(tab)
  11. {
  12. }
  13. public override Dictionary<string, object[]>? Selected()
  14. {
  15. return Grid is not null
  16. ? new Dictionary<string, object[]>
  17. {
  18. { typeof(TDetail).EntityName(), Grid.SelectedRows }
  19. }
  20. : null;
  21. }
  22. protected abstract void DoRefresh(TGrid grid, bool columns);
  23. protected override IDataModelSource Refresh()
  24. {
  25. var bInitialised = false;
  26. if (Grid == null)
  27. {
  28. Grid = new TGrid();
  29. Tab.Content = Grid;
  30. }
  31. else
  32. {
  33. bInitialised = true;
  34. }
  35. Grid.Master = Master;
  36. DoRefresh(Grid,!bInitialised);
  37. return Grid;
  38. }
  39. }