Ver código fonte

Fixed some bugs with DynamicGridColumns nto being constructed correctly.

Kenric Nugteren 4 meses atrás
pai
commit
ccff308299

+ 1 - 1
inabox.wpf/DynamicGrid/DynamicEditorForm/DynamicEditorGrid.xaml.cs

@@ -661,7 +661,7 @@ public partial class DynamicEditorGrid : UserControl, IDynamicEditorHost
                     if(parentEditor is not null)
                     {
                         parentEditor.EditorSequence = editors.Count;
-                        OnGridCustomiseEditor?.Invoke(this, new DynamicGridColumn { ColumnName = parent.Name }, parentEditor);
+                        OnGridCustomiseEditor?.Invoke(this, new DynamicGridColumn(parent), parentEditor);
                     }
                     if(parentEditor is not null && parentEditor.Editable.EditorVisible())
                     {

+ 34 - 18
inabox.wpf/DynamicGrid/DynamicGridColumn/DynamicGridColumn.cs

@@ -36,6 +36,33 @@ public class DynamicGridColumn : DynamicColumnBase
     {
         Editor = new NullEditor();
     }
+    public DynamicGridColumn(IProperty property)
+    {
+        ColumnName = property.Name;
+        Width = property.Editor.Width;
+        Alignment = property.Editor.Alignment;
+        Format = property.Editor.Format;
+        Editor = property.Editor.CloneEditor();
+        Caption = property.Caption;
+    }
+    public DynamicGridColumn(DynamicGridColumn column)
+    {
+        ColumnName = column.ColumnName;
+        Width = column.Width;
+        Caption = column.Caption;
+        Format = column.Format;
+        Alignment = column.Alignment;
+        Editor = column.Editor.CloneEditor();
+    }
+    public DynamicGridColumn(CoreGridColumn column)
+    {
+        ColumnName = column.Property.Name;
+        Width = column.Width;
+        Caption = column.Caption;
+        Format = column.Format;
+        Alignment = column.Alignment;
+        Editor = column.Editor.CloneEditor();
+    }
 
     [DynamicColumnNameEditor(Visible = Visible.Default)]
     [EditorSequence(1)]
@@ -70,28 +97,17 @@ public class DynamicGridColumn : DynamicColumnBase
 
     public DynamicGridColumn Copy()
     {
-        return new DynamicGridColumn
-        {
-            ColumnName = ColumnName,
-            Width = Width,
-            Caption = Caption,
-            Format = Format,
-            Alignment = Alignment,
-            Editor = Editor.CloneEditor()
-        };
+        return new(this);
+    }
+
+    public static DynamicGridColumn FromProperty(IProperty property)
+    {
+        return new DynamicGridColumn(property);
     }
 
     public static DynamicGridColumn FromCoreGridColumn(CoreGridColumn column)
     {
-        return new DynamicGridColumn
-        {
-            ColumnName = column.Property.Name,
-            Width = column.Width,
-            Caption = column.Caption,
-            Format = column.Format,
-            Alignment = column.Alignment,
-            Editor = column.Editor.CloneEditor()
-        };
+        return new DynamicGridColumn(column);
     }
 
     public static DynamicGridColumn? FromCoreColumn(CoreColumn column)

+ 2 - 10
inabox.wpf/DynamicGrid/DynamicGridColumn/DynamicGridColumns.cs

@@ -34,16 +34,8 @@ public class DynamicGridColumns : List<DynamicGridColumn>, IGlobalConfigurationS
                     }
                     else
                     {
-                        var col = new DynamicGridColumn
-                        {
-                            ColumnName = prop.Name,
-                            Width = prop.Editor.Width,
-                            Alignment = prop.Editor.Alignment,
-                            Format = prop.Editor.Format,
-                            Editor = prop.Editor.CloneEditor(),
-                            Caption = prop.Caption
-                        };
-                        value.Add(col);
+                        
+                        value.Add(new(prop));
                     }
                 }
             }

+ 1 - 1
inabox.wpf/DynamicGrid/Grids/DynamicDataGrid.cs

@@ -52,7 +52,7 @@ public class DynamicDataGrid<TEntity> : DynamicGrid<TEntity>, IDynamicDataGrid w
 
         foreach (var field in fields)
             if (!MasterColumns.Any(x => x.ColumnName == field.Name))
-                MasterColumns.Add(new DynamicGridColumn { ColumnName = field.Name });
+                MasterColumns.Add(new DynamicGridColumn(field));
 
         var cols = LookupFactory.DefineColumns<TEntity>();
 

+ 3 - 7
inabox.wpf/Reports/ReportGrid.cs

@@ -83,13 +83,9 @@ namespace InABox.Wpf.Reports
 
         protected override DynamicGridColumns LoadColumns()
         {
-            var columns = new DynamicGridColumns();
-            columns.Add(new DynamicGridColumn { ColumnName = "Name", Width = 0 });
-
-            //var col = new DynamicGridColumn { ColumnName = "PrinterName", Width = 0 };
-            //columns.Add(col);
-
-            columns.Add(new DynamicGridColumn { ColumnName = "Visible", Width = 50, Alignment = Alignment.MiddleCenter });
+            var columns = new DynamicGridColumns<ReportTemplate>();
+            columns.Add(x => x.Name, width: 0);
+            columns.Add(x => x.Visible, width: 50, alignment: Alignment.MiddleCenter);
             return columns;
         }