Пример #1
0
        public static void AddKnockoutDataBind(this IHtmlWriter writer, string name, DotvvmControl control, DotvvmProperty property, Action nullBindingAction = null,
                                               string valueUpdate = null, bool renderEvenInServerRenderingMode = false, bool setValueBack = false)
        {
            var expression = control.GetValueBinding(property);

            if (expression != null && (!control.RenderOnServer || renderEvenInServerRenderingMode))
            {
                writer.AddAttribute("data-bind", name + ": " + expression.GetKnockoutBindingExpression(), true, ", ");
                if (valueUpdate != null)
                {
                    writer.AddAttribute("data-bind", "valueUpdate: '" + valueUpdate + "'", true, ", ");
                }
            }
            else
            {
                if (nullBindingAction != null)
                {
                    nullBindingAction();
                }
                if (setValueBack && expression != null)
                {
                    control.SetValue(property, expression.Evaluate(control, property));
                }
            }
        }
Пример #2
0
 public static void AddKnockoutDataBind(this IHtmlWriter writer, string name, DotvvmControl control, DotvvmProperty property, Action nullBindingAction = null,
     string valueUpdate = null, bool renderEvenInServerRenderingMode = false, bool setValueBack = false)
 {
     var expression = control.GetValueBinding(property);
     if (expression != null && (!control.RenderOnServer || renderEvenInServerRenderingMode))
     {
         writer.AddAttribute("data-bind", name + ": " + expression.GetKnockoutBindingExpression(), true, ", ");
         if (valueUpdate != null)
         {
             writer.AddAttribute("data-bind", "valueUpdate: '" + valueUpdate + "'", true, ", ");
         }
     }
     else
     {
         if (nullBindingAction != null) nullBindingAction();
         if (setValueBack && expression != null) control.SetValue(property, expression.Evaluate(control, property));
     }
 }
Пример #3
0
        public static void TransferProperty(this DotvvmControl sourceControl, DotvvmControl targetControl, DotvvmProperty targetProperty,
                                            DotvvmProperty sourceProperty)
        {
            IBinding binding = sourceControl.GetBinding(sourceProperty);

            if (binding != null)
            {
                targetControl.SetBinding(targetProperty, binding);
            }
            else
            {
                var value = sourceProperty.GetValue(sourceControl);
                if (value != null)
                {
                    targetControl.SetValue(targetProperty, value);
                }
            }
        }