瀏覽代碼

Added new utility function for DynamicGridColumns

Kenric Nugteren 7 月之前
父節點
當前提交
9cecb76a7c
共有 2 個文件被更改,包括 24 次插入1 次删除
  1. 1 0
      InABox.Core/DatabaseSchema/DatabaseSchema.cs
  2. 23 1
      inabox.wpf/DynamicGrid/DynamicGridColumns.cs

+ 1 - 0
InABox.Core/DatabaseSchema/DatabaseSchema.cs

@@ -365,6 +365,7 @@ namespace InABox.Core
             return prop;
         }
         public static IProperty? Property<T>(Expression<Func<T, object?>> expression) => Property(typeof(T), CoreUtils.GetFullPropertyName(expression, "."));
+        public static IProperty? Property<T, TType>(Expression<Func<T, TType>> expression) => Property(typeof(T), CoreUtils.GetFullPropertyName(expression, "."));
 
         public static void InitializeObject<TObject>(TObject entity) where TObject : BaseObject
         {

+ 23 - 1
inabox.wpf/DynamicGrid/DynamicGridColumns.cs

@@ -29,7 +29,7 @@ public class DynamicGridColumns : List<DynamicGridColumn>, IGlobalConfigurationS
                         Width = prop.Editor.Width,
                         Alignment = prop.Editor.Alignment,
                         Format = prop.Editor.Format,
-                        Editor = prop.Editor,
+                        Editor = prop.Editor.CloneEditor(),
                         Caption = prop.Caption
                     };
                     _columnscache[type].Add(col);
@@ -56,6 +56,28 @@ public class DynamicGridColumns : List<DynamicGridColumn>, IGlobalConfigurationS
         Add(result);
         return result;
     }
+
+    public DynamicGridColumn Add<TType, TProperty>(
+        Expression<Func<TType, TProperty>> member,
+        int? width = null,
+        string? caption = null,
+        string? format = null,
+        Alignment? alignment = null
+    )
+    {
+        var prop = DatabaseSchema.Property(member);
+        var col = new DynamicGridColumn
+        {
+            ColumnName = prop.Name,
+            Width = width ?? prop.Editor.Width,
+            Alignment = alignment ?? prop.Editor.Alignment,
+            Format = format ?? prop.Editor.Format,
+            Editor = prop.Editor.CloneEditor(),
+            Caption = caption ?? prop.Caption
+        };
+        Add(col);
+        return col;
+    }
 }
 
 public class DynamicGridColumns<T> : DynamicGridColumns