Пример #1
0
        public static void OnCompilation(ResolvedControl control, BindingCompilationService bindingService)
        {
            // ComboBoxed does not have to have the DataSource property and then they don't use the CurrentIndexBindingProperty
            if (!control.HasProperty(DataSourceProperty))
            {
                return;
            }

            var dcChange = ControlTreeResolverBase.ApplyContextChange(control.DataContextTypeStack,
                                                                      new DataContextChangeAttribute[] { new ControlPropertyBindingDataContextChangeAttribute(nameof(DataSource)), new CollectionElementDataContextChangeAttribute(0) },
                                                                      control, null);
            var dataContext = DataContextStack.Create(ResolvedTypeDescriptor.ToSystemType(dcChange.type), control.DataContextTypeStack, extenstionParameters: dcChange.extensionParameters);

            control.SetProperty(new ResolvedPropertyBinding(Internal.CurrentIndexBindingProperty,
                                                            new ResolvedBinding(bindingService, new Compilation.BindingParserOptions(typeof(ValueBindingExpression)), dataContext,
                                                                                parsedExpression: Expression.Parameter(typeof(int), "_index").AddParameterAnnotation(
                                                                                    new BindingParameterAnnotation(dataContext, new CurrentCollectionIndexExtensionParameter())))));
        }