瀏覽代碼

Allowed for the grid of a MasterList to be overriden.

Kenric Nugteren 7 月之前
父節點
當前提交
8e26462cd4
共有 1 個文件被更改,包括 12 次插入4 次删除
  1. 12 4
      inabox.wpf/DynamicGrid/Controls/MasterList.xaml.cs

+ 12 - 4
inabox.wpf/DynamicGrid/Controls/MasterList.xaml.cs

@@ -30,7 +30,8 @@ namespace InABox.DynamicGrid
         /// <param name="allowallitems">Show an "All Items" entry at tge top of the Groups List Box</param>
         /// <param name="dataGrid">If null, finds a DynamicDataGrid of the specified entity type. 
         /// Otherwise, MasterList uses this parameter as the DynamicGrid type</param>
-        public MasterList(Type type, string? groupby = null, string? selectedgroup = null, bool allowallitems = false, Type? dataGrid = null)
+        public MasterList(Type type, string? groupby = null, string? selectedgroup = null, bool allowallitems = false, Type? dataGrid = null,
+            IDynamicGrid? dynamicGrid = null)
         {
             InitializeComponent();
             Type = type;
@@ -39,12 +40,19 @@ namespace InABox.DynamicGrid
             CurrentGroup = selectedgroup;
             GroupBy = groupby;
 
-            if(dataGrid == null)
+            if(dynamicGrid is null)
             {
-                dataGrid = DynamicGridUtils.FindDynamicGrid(typeof(DynamicDataGrid<>), type);
+                if(dataGrid == null)
+                {
+                    dataGrid = DynamicGridUtils.FindDynamicGrid(typeof(DynamicDataGrid<>), type);
+                }
+                grid = (Activator.CreateInstance(dataGrid) as IDynamicGrid) ?? throw new Exception($"Invalid Grid Type {dataGrid}");
+            }
+            else
+            {
+                grid = dynamicGrid;
             }
 
-            grid = (IDynamicGrid)Activator.CreateInstance(dataGrid);
             grid.Margin = new Thickness(5, 5, 5, 5);
             ((DependencyObject)grid).SetValue(Grid.ColumnProperty, 1);
             ((DependencyObject)grid).SetValue(Grid.RowProperty, 0);