diff --git a/src/Framework/Framework/Compilation/Binding/GeneralBindingPropertyResolvers.cs b/src/Framework/Framework/Compilation/Binding/GeneralBindingPropertyResolvers.cs
index e0ffccd615..e29eb171f0 100644
--- a/src/Framework/Framework/Compilation/Binding/GeneralBindingPropertyResolvers.cs
+++ b/src/Framework/Framework/Compilation/Binding/GeneralBindingPropertyResolvers.cs
@@ -427,10 +427,9 @@ public ThisBindingProperty GetThisBinding(IBinding binding, DataContextStack sta
public CollectionElementDataContextBindingProperty GetCollectionElementDataContext(DataContextStack dataContext, ResultTypeBindingProperty resultType)
{
- return new CollectionElementDataContextBindingProperty(DataContextStack.Create(
+ return new CollectionElementDataContextBindingProperty(DataContextStack.CreateCollectionElement(
ReflectionUtils.GetEnumerableType(resultType.Type).NotNull(),
- parent: dataContext,
- extensionParameters: new CollectionElementDataContextChangeAttribute(0).GetExtensionParameters(new ResolvedTypeDescriptor(dataContext.DataContextType)).ToArray()
+ dataContext
));
}
diff --git a/src/Framework/Framework/Compilation/ControlTree/DataContextStack.cs b/src/Framework/Framework/Compilation/ControlTree/DataContextStack.cs
index a655cadc35..f43a04f963 100644
--- a/src/Framework/Framework/Compilation/ControlTree/DataContextStack.cs
+++ b/src/Framework/Framework/Compilation/ControlTree/DataContextStack.cs
@@ -4,6 +4,7 @@
using System.Collections.Immutable;
using System.Linq;
using System.Runtime.CompilerServices;
+using DotVVM.Framework.Binding;
using DotVVM.Framework.Compilation.ControlTree.Resolved;
using DotVVM.Framework.Utils;
using FastExpressionCompiler;
@@ -172,5 +173,23 @@ public static DataContextStack Create(Type type,
var dcs = new DataContextStack(type, parent, imports, extensionParameters, bindingPropertyResolvers);
return dcs;// internCache.GetValue(dcs, _ => dcs);
}
+
+
+ /// Creates a new data context level with _index and _collection extension parameters.
+ public static DataContextStack CreateCollectionElement(Type elementType,
+ DataContextStack? parent = null,
+ IReadOnlyList? imports = null,
+ IReadOnlyList? extensionParameters = null,
+ IReadOnlyList? bindingPropertyResolvers = null)
+ {
+ var indexParameters = new CollectionElementDataContextChangeAttribute(0).GetExtensionParameters(new ResolvedTypeDescriptor(elementType.MakeArrayType()));
+ extensionParameters = extensionParameters is null ? indexParameters.ToArray() : extensionParameters.Concat(indexParameters).ToArray();
+ return DataContextStack.Create(
+ elementType, parent,
+ imports: imports,
+ extensionParameters: extensionParameters,
+ bindingPropertyResolvers: bindingPropertyResolvers
+ );
+ }
}
}