Esempio n. 1
0
        public ExcelContextItemButton(IBindingContextElement parent, IBindingDefinition bindingDefinition)
            : base(parent, bindingDefinition)
        {
            CanNotify = bindingDefinition?.CanNotify ?? false;
            excelBindingDefinitionButton = bindingDefinition as ExcelBindingDefinitionButton;

            if (CanNotify)
            {
                objectsToNotify = excelBindingDefinitionButton.GetObjectsToNotify(DataSource);
                if (objectsToNotify != null)
                {
                    foreach (INotifyPropertyChanged obj in objectsToNotify)
                    {
                        obj.PropertyChanged += OnPropertyChanged;
                    }
                }
            }

            if (excelBindingDefinitionButton.EnablePropertyInfo != null)
            {
                EnablePropertyGet = excelBindingDefinitionButton.EnablePropertyInfo.GetGetMethod();
                if (EnablePropertyGet != null)
                {
                    if (!EnablePropertyGet.IsStatic)
                    {
                        if (ParentElement.DataSource != null && ParentElement.DataSource is INotifyPropertyChanged)
                        {
                            EnableProperty = (INotifyPropertyChanged)ParentElement.DataSource;
                            EnableProperty.PropertyChanged += OnPropertyChanged;
                        }
                    }
                }
            }
        }
        public static ExcelBindingDefinitionButton CreateInstance(ExcelTemplateDefinition templateDefinition, string definition)
        {
            ExcelBindingDefinitionButton ret = null;

            if (!string.IsNullOrEmpty(definition))
            {
                try
                {
                    ExcelButtonDefinition        excelButtonDefinition = definition.Deserialize <ExcelButtonDefinition>();
                    BindingDefinitionDescription definitionDescription = BindingDefinitionDescription.CreateBindingDescription(templateDefinition, excelButtonDefinition.Label, excelButtonDefinition.Label);
                    ret = new ExcelBindingDefinitionButton(definitionDescription, templateDefinition, excelButtonDefinition);
                }
                catch (Exception ex)
                {
                    string message = $"Cannot retrieve the button dataAccessor '{definition.EmptyIfNull()}'. {ex.Message}";
                    throw new EtkException(message);
                }
            }
            return(ret);
        }
Esempio n. 3
0
        public void CreateControl(ExcelInterop.Range range)
        {
            ExcelBindingDefinitionButton definition = (ExcelBindingDefinitionButton)BindingDefinition;

            button = new ExcelButton(range, definition.Definition);
            //bool isStatic = definition.Command == null ? false : definition.Command.IsStatic;
            button.SetCommand(definition.Command, ParentElement.DataSource, definition.OnClickWithRange);

            ResolveBinding();

            if (EnableProperty != null)
            {
                if (EnablePropertyGet.IsStatic)
                {
                    button.Enable = (bool)EnablePropertyGet.Invoke(null, null);
                }
                else
                {
                    button.Enable = (bool)EnablePropertyGet.Invoke(ParentElement.DataSource, null);
                }
            }
        }