Exemple #1
0
        public static CommandBindingExpression RegisterExtensionCommand(this DotvvmControl control, Delegate action, string methodUsageId)
        {
            var id           = control.GetDotvvmUniqueId() + methodUsageId;
            var propertyName = control.GetType().FullName + "/" + methodUsageId;
            var property     = DotvvmProperty.Register <object, ExtensionCommands>(propertyName);
            var binding      = new CommandBindingExpression(action, id);

            control.SetBinding(property, binding);
            return(binding);
        }
Exemple #2
0
        public static CommandBindingExpression RegisterExtensionCommand(this DotvvmControl control, Delegate action, string methodUsageId)
        {
            var bindingService = control.GetValue(Internal.RequestContextProperty).CastTo <IDotvvmRequestContext>()
                                 .Configuration.ServiceProvider.GetRequiredService <BindingCompilationService>();
            var id           = control.GetDotvvmUniqueId() + methodUsageId;
            var propertyName = control.GetType().FullName + "/" + methodUsageId;
            var property     = DotvvmProperty.ResolveProperty(typeof(PropertyBox), propertyName) ?? DotvvmProperty.Register(propertyName, typeof(object), typeof(PropertyBox), null, false, null, typeof(PropertyBox), throwOnDuplicitRegistration: false);
            var binding      = new CommandBindingExpression(bindingService, action, id);

            control.SetBinding(property, binding);
            return(binding);
        }
        public static CommandBindingExpression RegisterExtensionCommand(this DotvvmControl control, Delegate action, string methodUsageId)
        {
            var bindingService = control.GetValue(Internal.RequestContextProperty).CastTo <IDotvvmRequestContext>()
                                 .Configuration.ServiceLocator.GetService <BindingCompilationService>();
            var id           = control.GetDotvvmUniqueId() + methodUsageId;
            var propertyName = control.GetType().FullName + "/" + methodUsageId;
            var property     = DotvvmProperty.Register <object, PropertyBox>(propertyName);
            var binding      = new CommandBindingExpression(bindingService, action, id);

            control.SetBinding(property, binding);
            return(binding);
        }
        /// <summary>
        /// Finds the binding of the specified type on the specified viewmodel path.
        /// </summary>
        private FindBindingResult FindCommandBinding(string[] path, string commandId, DotvvmControl viewRootControl, string validationTargetPath)
        {
            // walk the control tree and find the path
            CommandBindingExpression resultBinding  = null;
            DotvvmControl            resultControl  = null;
            DotvvmProperty           resultProperty = null;

            var walker = new ControlTreeWalker(viewRootControl);

            walker.ProcessControlTree((control) =>
            {
                // compare path
                if (resultBinding == null && ViewModelPathComparer.AreEqual(path, walker.CurrentPathArray))
                {
                    // find bindings of current control
                    var binding = control.GetAllBindings().Where(p => p.Value is CommandBindingExpression)
                                  .FirstOrDefault(b => b.Value.BindingId == commandId);
                    if (binding.Key != null)
                    {
                        // we have found the binding, now get the validation path
                        var currentValidationTargetPath = KnockoutHelper.GetValidationTargetExpression(control);
                        if (currentValidationTargetPath == validationTargetPath)
                        {
                            // the validation path is equal, we have found the binding
                            resultBinding  = (CommandBindingExpression)binding.Value;
                            resultControl  = control;
                            resultProperty = binding.Key;
                        }
                    }
                }
            });

            return(new FindBindingResult
            {
                Binding = resultBinding,
                Control = resultControl,
                Property = resultProperty
            });
        }
Exemple #5
0
        public virtual void CreateHeaderControls(DotvvmRequestContext context, GridView gridView, Action<string> sortCommand, HtmlGenericControl cell)
        {
            if (AllowSorting)
            {
                if (sortCommand == null)
                {
                    throw new Exception("Cannot use column sorting where no sort command is specified. Either put IGridViewDataSet in the DataSource property of the GridView, or set the SortChanged command on the GridView to implement custom sorting logic!");
                }

                var sortExpression = GetSortExpression();

                var linkButton = new LinkButton() { Text = HeaderText };
                cell.Children.Add(linkButton);
                var bindingId = linkButton.GetValue(Internal.UniqueIDProperty) + "_sortBinding";
                var binding = new CommandBindingExpression((o, i) => { sortCommand(sortExpression); return null; }, bindingId);
                linkButton.SetBinding(ButtonBase.ClickProperty, binding);
            }
            else
            {
                var literal = new Literal(HeaderText);
                cell.Children.Add(literal);
            }
        }