浏览代码

Add ItemsControl.PreparingContainer event (#14153)

Tom Edwards 1 年之前
父节点
当前提交
353ad7dbd4
共有 1 个文件被更改,包括 11 次插入0 次删除
  1. 11 0
      src/Avalonia.Controls/ItemsControl.cs

+ 11 - 0
src/Avalonia.Controls/ItemsControl.cs

@@ -212,6 +212,15 @@ namespace Avalonia.Controls
             remove => _childIndexChanged -= value;
             remove => _childIndexChanged -= value;
         }
         }
 
 
+        /// <summary>
+        /// Occurs immediately before a container is prepared for use.
+        /// </summary>
+        /// <remarks>
+        /// The prepared element might be newly created or an existing container that is being re-
+        /// used.
+        /// </remarks>
+        public event EventHandler<ContainerPreparedEventArgs>? PreparingContainer;
+
         /// <summary>
         /// <summary>
         /// Occurs each time a container is prepared for use.
         /// Occurs each time a container is prepared for use.
         /// </summary>
         /// </summary>
@@ -702,6 +711,8 @@ namespace Avalonia.Controls
 
 
         internal void PrepareItemContainer(Control container, object? item, int index)
         internal void PrepareItemContainer(Control container, object? item, int index)
         {
         {
+            PreparingContainer?.Invoke(this, new(container, index));
+
             // If the container has no theme set, or we've already applied our ItemContainerTheme
             // If the container has no theme set, or we've already applied our ItemContainerTheme
             // (and it hasn't changed since) then we're in control of the container's Theme and may
             // (and it hasn't changed since) then we're in control of the container's Theme and may
             // need to update it.
             // need to update it.