示例#1
0
 public void Add(string name, DotvvmControl control, DotvvmProperty property, Action nullBindingAction)
 {
     var binding = control.GetValueBinding(property);
     if (binding == null)
     {
         nullBindingAction();
     }
     else
     {
         entries.Add(new KnockoutBindingInfo() { Name = name, Expression = control.GetValueBinding(property).GetKnockoutBindingExpression() });
     }
 }
        public static void AddNegation(this KnockoutBindingGroup group, string name, DotvvmControl control, DotvvmProperty property, Func <bool> nullBindingAction)
        {
            var binding = control.GetValueBinding(property);

            if (binding == null)
            {
                group.Add(name, (!nullBindingAction()).ToString().ToLower());
            }
            else
            {
                string expression = control.GetValueBinding(property).GetKnockoutBindingExpression();
                group.Add(name, $"!{expression}()");
            }
        }
        public static void AddExtender(this KnockoutBindingGroup group, string name, DotvvmControl control, DotvvmProperty property, string extenderName)
        {
            var binding = control.GetValueBinding(property);

            if (binding == null)
            {
                throw new NotSupportedException();
                //group.Add(name, (!nullBindingAction()).ToString().ToLower());
            }
            else
            {
                string expression = control.GetValueBinding(property).GetKnockoutBindingExpression();
                group.Add(name, $"{expression}.{extenderName}");
            }
        }
        public static void AddSimpleBinding(this KnockoutBindingGroup group, string name, DotvvmControl control, DotvvmProperty property)
        {
            var binding = control.GetValueBinding(property);

            if (binding == null)
            {
                string value = JsonConvert.ToString(property.GetValue(control));
                group.Add(name, value, false);
            }
            else
            {
                string expression = control.GetValueBinding(property).GetKnockoutBindingExpression();
                group.Add(name, $"{expression}");
            }
        }
示例#5
0
        public void Add(string name, DotvvmControl control, DotvvmProperty property, Action nullBindingAction)
        {
            var binding = control.GetValueBinding(property);

            if (binding == null)
            {
                nullBindingAction();
            }
            else
            {
                entries.Add(new KnockoutBindingInfo()
                {
                    Name = name, Expression = control.GetValueBinding(property).GetKnockoutBindingExpression()
                });
            }
        }
示例#6
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));
                }
            }
        }
示例#7
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));
     }
 }
示例#8
0
        /// <summary>
        /// Processes the control tree.
        /// </summary>
        private void ProcessControlTreeCore(DotvvmControl control, Action <DotvvmControl> 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.GetChildren())
            {
                ProcessControlTreeCore(child, action);
            }

            if (hasDataContext)
            {
                CurrentPath.Pop();
                RefreshCurrentPathArray();
            }
        }
示例#9
0
 public static void WriteKnockoutDataBindComment(this IHtmlWriter writer, string name, DotvvmControl control, DotvvmProperty property)
 {
     writer.WriteUnencodedText($"<!-- ko { name }: { control.GetValueBinding(property).GetKnockoutBindingExpression() } -->");
 }
示例#10
0
 public static void WriteKnockoutDataBindComment(this IHtmlWriter writer, string name, DotvvmControl control, DotvvmProperty property)
 {
     writer.WriteUnencodedText($"<!-- ko { name }: { control.GetValueBinding(property).GetKnockoutBindingExpression() } -->");
 }