public TValue this[string key]
 {
     get
     {
         return((TValue)control.GetValue(group.GetDotvvmProperty(key)));
     }
     set
     {
         control.SetValue(group.GetDotvvmProperty(key), value);
     }
 }
Exemple #2
0
        private object ResolveStaticCommandService(DotvvmBindableObject c, Type type)
        {
            var context = (IDotvvmRequestContext)c.GetValue(Internal.RequestContextProperty, true);

#pragma warning disable CS0618
            return(context.Services.GetRequiredService <IStaticCommandServiceLoader>().GetStaticCommandService(type, context));

#pragma warning restore CS0618
        }
Exemple #3
0
        /// <summary>
        /// Gets all data context on the path to root
        /// </summary>
        public static object[] GetDataContexts(DotvvmBindableObject contextControl, bool seeThis)
        {
            var context = seeThis ? contextControl.GetValue(DotvvmBindableObject.DataContextProperty, false) : null;

            return
                ((context == null ? new object[0] : new[] { context })
                 .Concat(contextControl.GetAllAncestors().OfType <DotvvmBindableObject>()
                         .Where(c => c.properties.ContainsKey(DotvvmBindableObject.DataContextProperty))
                         .Select(c => c.GetValue(DotvvmBindableObject.DataContextProperty, false)))
                 .ToArray());
        }
Exemple #4
0
        public static void CopyProperty(DotvvmBindableObject source, DotvvmProperty sourceProperty, DotvvmBindableObject target, DotvvmProperty targetProperty)
        {
            var binding = source.GetValueBinding(sourceProperty);

            if (binding != null)
            {
                target.SetBinding(targetProperty, binding);
            }
            else
            {
                target.SetValue(targetProperty, source.GetValue(sourceProperty));
            }
        }
Exemple #5
0
        /// <summary>
        /// Processes the control tree.
        /// </summary>
        private void ProcessControlTreeCore(DotvvmBindableObject control, Action <DotvvmBindableObject> action)
        {
            // if there is a DataContext binding, locate the correct token
            var hasDataContext = false;
            var pathValue      = control.GetValue(Internal.PathFragmentProperty, false);

            if (pathValue != null)
            {
                CurrentPath.Push(pathValue as string);
                RefreshCurrentPathArray();
                hasDataContext = true;
            }
            else
            {
                var binding = control.GetValueBinding(DotvvmBindableObject.DataContextProperty, false);
                if (binding != null)
                {
                    CurrentPath.Push(binding.GetKnockoutBindingExpression());
                    RefreshCurrentPathArray();
                    hasDataContext = true;
                }
            }

            action(control);

            // go through all children
            foreach (var child in control.GetLogicalChildren())
            {
                ProcessControlTreeCore(child, action);
            }

            if (hasDataContext)
            {
                CurrentPath.Pop();
                RefreshCurrentPathArray();
            }
        }
Exemple #6
0
        /// <summary>
        /// Processes the control tree.
        /// </summary>
        private void ProcessControlTreeCore(DotvvmBindableObject control, Action<DotvvmBindableObject> action)
        {
            // if there is a DataContext binding, locate the correct token
            var hasDataContext = false;
            var pathValue = control.GetValue(Internal.PathFragmentProperty, false);
            if (pathValue != null)
            {
                CurrentPath.Push(pathValue as string);
                RefreshCurrentPathArray();
                hasDataContext = true;
            }
            else
            {
                var binding = control.GetValueBinding(DotvvmBindableObject.DataContextProperty, false);
                if (binding != null)
                {
                    CurrentPath.Push(binding.GetKnockoutBindingExpression());
                    RefreshCurrentPathArray();
                    hasDataContext = true;
                }
            }

            action(control);

            // go through all children
            foreach (var child in control.GetLogicalChildren())
            {
                ProcessControlTreeCore(child, action);
            }

            if (hasDataContext)
            {
                CurrentPath.Pop();
                RefreshCurrentPathArray();
            }
        }
        private object ResolveStaticCommandService(DotvvmBindableObject c, Type type)
        {
            var context = (IDotvvmRequestContext)c.GetValue(Internal.RequestContextProperty, true);

            return(context.Services.GetService <IStaticCommandServiceLoader>().GetStaticCommandService(type, context));
        }
Exemple #8
0
 public static string?GetDataContextPathFragment(this DotvvmBindableObject currentControl) =>
 (string?)currentControl.GetValue(Internal.PathFragmentProperty, inherit: false) ??
 (currentControl.GetBinding(DotvvmBindableObject.DataContextProperty, inherit: false) is IValueBinding binding ?
Exemple #9
0
        /// <summary>
        /// Gets the validation target expression.
        /// </summary>
        public static string GetValidationTargetExpression(DotvvmBindableObject control)
        {
            if (!(bool)control.GetValue(Validation.EnabledProperty))
            {
                return null;
            }

            // find the closest control
            int dataSourceChanges;
            var validationTargetControl = control.GetClosestWithPropertyValue(out dataSourceChanges, c => c.GetValueBinding(Validation.TargetProperty) != null);
            if (validationTargetControl == null)
            {
                return "$root";
            }

            // reparent the expression to work in current DataContext
            // FIXME: This does not work:
            var validationBindingExpression = validationTargetControl.GetValueBinding(Validation.TargetProperty);
            string validationExpression = validationBindingExpression.GetKnockoutBindingExpression();
            validationExpression = string.Join("", Enumerable.Range(0, dataSourceChanges).Select(i => "$parent.")) + validationExpression;

            return validationExpression;
        }