/// <summary>
        /// Gets the view model path expression.
        /// </summary>
        public override string GetViewModelPathExpression(RedwoodBindableControl control, RedwoodProperty property)
        {
            // find the parent markup control and calculate number of DataContext changes
            int numberOfDataContextChanges;
            var current = control.GetClosestControlBindingTarget(out numberOfDataContextChanges) as RedwoodBindableControl;

            current.EnsureControlHasId();
            return string.Join(".", Enumerable.Range(0, numberOfDataContextChanges).Select(i => "_parent").Concat(new[] { "_controlState_" + current.ID, Expression }));
        }
        /// <summary>
        /// Evaluates the specified expression.
        /// </summary>
        public override object Evaluate(RedwoodBindableControl control, RedwoodProperty property)
        {
            ValidateExpression(Expression);

            // find the parent markup control and calculate number of DataContext changes
            int numberOfDataContextChanges;
            var current = control.GetClosestControlBindingTarget(out numberOfDataContextChanges) as RedwoodBindableControl;

            if (current == null || !current.RequiresControlState)
            {
                throw new Exception("The {controlState: ...} binding can only be used in a markup control that supports ControlState!");    // TODO: exception handling
            }
            else
            {
                object value;
                return current.ControlState.TryGetValue(Expression, out value) ? value : DefaultValue;
            }
        }
Exemplo n.º 3
0
        /// <summary>
        /// Finds the binding of the specified type on the specified viewmodel path.
        /// </summary>
        private CommandBindingExpression FindCommandBinding(string[] path, string command, RedwoodControl viewRootControl, ref string validationTargetPath, out RedwoodBindableControl targetControl, out RedwoodProperty targetProperty)
        {
            // walk the control tree and find the path
            CommandBindingExpression result = null;
            RedwoodBindableControl resultControl = null;
            RedwoodProperty resultProperty = null;
            string resultValidationTargetPath = validationTargetPath;

            var walker = new NonEvaluatingControlTreeWalker(viewRootControl);
            walker.ProcessControlTree((ViewModel, control) =>
            {
                // compare path
                if (result == null && control is RedwoodBindableControl && ViewModelPathComparer.AreEqual(path, walker.CurrentPathArray))
                {
                    // find bindings of current control
                    var bindableControl = (RedwoodBindableControl)control;
                    var binding = bindableControl.GetAllBindings().Where(p => p.Value is CommandBindingExpression)
                        .FirstOrDefault(b => b.Value.Expression == command);
                    if (binding.Key != null)
                    {
                        // we have found the binding, now get the validation path
                        var currentValidationTargetPath = KnockoutHelper.GetValidationTargetExpression(bindableControl, true);
                        if (currentValidationTargetPath == resultValidationTargetPath)
                        {
                            // the validation path is equal, we have found the binding
                            result = (CommandBindingExpression)binding.Value;
                            resultControl = bindableControl;
                            resultProperty = binding.Key;
                            resultValidationTargetPath = KnockoutHelper.GetValidationTargetExpression(bindableControl, false);
                        }
                    }
                }
            });

            validationTargetPath = resultValidationTargetPath;
            targetControl = resultControl;
            targetProperty = resultProperty;
            return result;
        }
        /// <summary>
        /// Translates the expression to client script.
        /// </summary>
        public override string TranslateToClientScript(RedwoodBindableControl control, RedwoodProperty property)
        {
            ValidateExpression(Expression);

            // find the parent markup control and calculate number of DataContext changes
            int numberOfDataContextChanges;
            var current = control.GetClosestControlBindingTarget(out numberOfDataContextChanges) as RedwoodBindableControl;

            current.EnsureControlHasId();
            return string.Join(".", Enumerable.Range(0, numberOfDataContextChanges).Select(i => "$parent").Concat(new[] { "$controlState()", current.ID + "()", Expression }));
        }
 /// <summary>
 /// Updates the value.
 /// </summary>
 public override void UpdateSource(object value, RedwoodBindableControl control, RedwoodProperty property)
 {
     control.ControlState[property.Name] = value;
 }
Exemplo n.º 6
0
 /// <summary>
 /// Evaluates the binding.
 /// </summary>
 public override object Evaluate(RedwoodBindableControl control, RedwoodProperty property)
 {
     // TODO: implement server evaluation
     throw new NotImplementedException();
 }
Exemplo n.º 7
0
 /// <summary>
 /// Translates the binding to client script.
 /// </summary>
 /// <param name="control"></param>
 /// <param name="property"></param>
 public override string TranslateToClientScript(RedwoodBindableControl control, RedwoodProperty property)
 {
     return translator.Translate(Expression);
 }
Exemplo n.º 8
0
 /// <summary>
 /// Translates the binding to client script.
 /// </summary>
 /// <param name="control"></param>
 /// <param name="property"></param>
 public abstract string TranslateToClientScript(RedwoodBindableControl control, RedwoodProperty property);
Exemplo n.º 9
0
 /// <summary>
 /// Evaluates the binding.
 /// </summary>
 public abstract object Evaluate(RedwoodBindableControl control, RedwoodProperty property);
Exemplo n.º 10
0
 /// <summary>
 /// Updates the viewModel with the new value.
 /// </summary>
 public virtual void UpdateSource(object value, RedwoodBindableControl control, RedwoodProperty property)
 {
     object target;
     var propertyInfo = evaluator.EvaluateProperty(this, property, control, out target);
     propertyInfo.SetValue(target, ReflectionUtils.ConvertValue(value, propertyInfo.PropertyType));
 }
Exemplo n.º 11
0
 /// <summary>
 /// Gets the view model path expression.
 /// </summary>
 public virtual string GetViewModelPathExpression(RedwoodBindableControl control, RedwoodProperty property)
 {
     return Expression;
 }
Exemplo n.º 12
0
 /// <summary>
 /// Evaluates the binding.
 /// </summary>
 public override object Evaluate(RedwoodBindableControl control, RedwoodProperty property)
 {
     return evaluator.Evaluate(this, property, control);
 }