瀏覽代碼

DynamicEditorForm: Added the 'OnCreateEditorControl' event

Kenric Nugteren 4 月之前
父節點
當前提交
fd205c3aab

+ 2 - 0
inabox.wpf/DynamicGrid/DynamicEditorForm/DynamicEditorForm.xaml.cs

@@ -85,6 +85,8 @@ public partial class DynamicEditorForm : ThemableChromelessWindow, IDynamicEdito
     public event OnFormCustomiseEditor? OnFormCustomiseEditor { add => Form.OnFormCustomiseEditor += value; remove => Form.OnFormCustomiseEditor -= value; }
 
     public OnReconfigureEditors? OnReconfigureEditors { get => Form.OnReconfigureEditors; set { Form.OnReconfigureEditors = value; } }
+
+    public event OnCreateEditorControl? OnCreateEditorControl { add => Form.OnCreateEditorControl += value; remove => Form.OnCreateEditorControl -= value; }
     
     public event OnAfterEditorValueChanged? OnAfterEditorValueChanged { add => Form.OnAfterEditorValueChanged += value; remove => Form.OnAfterEditorValueChanged -= value; }
     public event EditorValueChangedHandler? OnEditorValueChanged { add => Form.OnEditorValueChanged += value; remove => Form.OnEditorValueChanged -= value; }

+ 8 - 0
inabox.wpf/DynamicGrid/DynamicEditorForm/DynamicEditorGrid.xaml.cs

@@ -164,6 +164,7 @@ public partial class DynamicEditorGrid : UserControl, IDynamicEditorHost
     public event OnAfterEditorValueChanged? OnAfterEditorValueChanged;
 
     public event OnReconfigureEditors? OnReconfigureEditors;
+    public event OnCreateEditorControl? OnCreateEditorControl;
     
     public event OnDefineLookupFilter? OnDefineFilter;
 
@@ -204,6 +205,11 @@ public partial class DynamicEditorGrid : UserControl, IDynamicEditorHost
 
     #region Edit Page
 
+    private void CreateEditorControl(string column, BaseEditor editor, IDynamicEditorControl control)
+    {
+        OnCreateEditorControl?.Invoke(column, editor, control);
+    }
+
     public class DynamicEditPage : ContentControl, IDynamicEditorPage
     {
 
@@ -311,6 +317,8 @@ public partial class DynamicEditorGrid : UserControl, IDynamicEditorHost
                 element.SetValue(Grid.RowProperty, Grid.RowDefinitions.Count - 1);
                 element.SetValue(Grid.ColumnProperty, 1);
                 Grid.Children.Add(element);
+
+                EditorGrid.CreateEditorControl(columnName, editor, element);
             }
         }
 

+ 2 - 1
inabox.wpf/DynamicGrid/DynamicEditorForm/EmbeddedDynamicEditorForm.xaml

@@ -41,7 +41,8 @@
             OnGetEditor="Editor_OnGetEditor"
             OnGetPropertyValue="Editor_OnGetPropertyValue"
             OnSetPropertyValue="Editor_OnSetPropertyValue"
-            OnReload="Editor_OnReload"/>
+            OnReload="Editor_OnReload"
+            OnCreateEditorControl="Editor_OnCreateEditorControl"/>
 
         <StackPanel 
             Grid.Row="1" 

+ 7 - 0
inabox.wpf/DynamicGrid/DynamicEditorForm/EmbeddedDynamicEditorForm.xaml.cs

@@ -199,6 +199,7 @@ namespace InABox.DynamicGrid
         public event OnFormCustomiseEditor? OnFormCustomiseEditor;
         public OnReconfigureEditors? OnReconfigureEditors { get; set; }
 
+        public event OnCreateEditorControl? OnCreateEditorControl;
         public event EditorValueChangedHandler? OnEditorValueChanged;
         public event OnAfterEditorValueChanged? OnAfterEditorValueChanged;
         
@@ -241,6 +242,7 @@ namespace InABox.DynamicGrid
         private void ClearEvents()
         {
             // These are events that are set by the grid/host.
+            OnCreateEditorControl = null;
             OnEditorValueChanged = null;
             OnFormCustomiseEditor = null;
             OnAfterEditorValueChanged = null;
@@ -541,5 +543,10 @@ namespace InABox.DynamicGrid
         {
             OnReload?.Invoke(this);
         }
+
+        private void Editor_OnCreateEditorControl(string column, BaseEditor editor, IDynamicEditorControl control)
+        {
+            OnCreateEditorControl?.Invoke(column, editor, control);
+        }
     }
 }

+ 1 - 0
inabox.wpf/DynamicGrid/DynamicEditorForm/IDynamicEditorForm.cs

@@ -23,6 +23,7 @@ namespace InABox.DynamicGrid
         DefineEditorEventHandler? OnDefineEditor { set; }
         event OnFormCustomiseEditor? OnFormCustomiseEditor;
         OnReconfigureEditors? OnReconfigureEditors { set; }
+        event OnCreateEditorControl? OnCreateEditorControl;
 
         event OnAfterEditorValueChanged? OnAfterEditorValueChanged;
         event EditorValueChangedHandler? OnEditorValueChanged;

+ 2 - 0
inabox.wpf/DynamicGrid/DynamicGridCommon.cs

@@ -415,6 +415,8 @@ public delegate void OnLoadEditorButtons<T>(T item, DynamicEditorButtons buttons
 
 public delegate void OnReconfigureEditors(DynamicEditorGrid sender);
 
+public delegate void OnCreateEditorControl(string column, BaseEditor editor, IDynamicEditorControl control);
+
 public class AfterEditorValueChangedArgs
 {
     public string ColumnName { get; set; }

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

@@ -523,6 +523,8 @@ public abstract class DynamicGrid<T> : BaseDynamicGrid, IDynamicGridUIComponentP
 
         editor.OnReconfigureEditors = g => DoReconfigureEditors(g, items);
 
+        editor.OnCreateEditorControl += OnCreateEditorControl;
+
         editor.OnValidateData += (o, i) => ValidateData(items);
 
         editor.OnSelectPage += SelectPage;
@@ -556,7 +558,11 @@ public abstract class DynamicGrid<T> : BaseDynamicGrid, IDynamicGridUIComponentP
         editor.Items = items;
         AfterLoad(editor, items);
     }
-    
+
+    protected virtual void OnCreateEditorControl(string column, BaseEditor editor, IDynamicEditorControl control)
+    {
+    }
+
     private void DoCustomiseEditor(IDynamicEditorForm sender, object[] items, DynamicGridColumn column, BaseEditor editor)
     {
         CustomiseEditor(sender, (T[])items, column, editor);