public static ExcelBindingDefinitionWithFormula CreateInstance(ExcelTemplateDefinition templateDefinition, BindingDefinitionDescription definition) { try { IBindingDefinition formulaBindingDefinition = null; IBindingDefinition targetBindingDefinition = null; if (!string.IsNullOrEmpty(definition.Formula)) { BindingDefinitionDescription formulaBindingDefinitionDescription = BindingDefinitionDescription.CreateBindingDescription(templateDefinition, definition.Formula, definition.Formula); formulaBindingDefinition = BindingDefinitionFactory.CreateInstances(templateDefinition, formulaBindingDefinitionDescription); } if (!string.IsNullOrEmpty(definition.BindingExpression)) { string bindingExpression = $"{{{definition.BindingExpression}}}"; BindingDefinitionDescription targetBindingDefinitionDescription = BindingDefinitionDescription.CreateBindingDescription(templateDefinition, bindingExpression, bindingExpression); targetBindingDefinition = BindingDefinitionFactory.CreateInstances(templateDefinition, targetBindingDefinitionDescription); } ExcelBindingDefinitionWithFormula ret = new ExcelBindingDefinitionWithFormula(definition, targetBindingDefinition, formulaBindingDefinition); return(ret); } catch (Exception ex) { string message = $"Cannot create the 'ExcelBindingDefinitionWithFormula' from '{definition.BindingExpression ?? string.Empty}'. {ex.Message}"; throw new EtkException(message); } }
public ExcelContextItemWithFormula(IBindingContextElement parent, IBindingDefinition bindingDefinition) : base(parent, bindingDefinition) { excelBindingDefinitionWithFormula = bindingDefinition as ExcelBindingDefinitionWithFormula; CanNotify = excelBindingDefinitionWithFormula.CanNotify; if (excelBindingDefinitionWithFormula.FormulaBindingDefinition != null) { formulaBindingContext = excelBindingDefinitionWithFormula.FormulaBindingDefinition.ContextItemFactory(parent); } if (CanNotify) { objectsToNotify = excelBindingDefinitionWithFormula.GetObjectsToNotify(DataSource); if (objectsToNotify != null) { foreach (INotifyPropertyChanged obj in objectsToNotify) { obj.PropertyChanged += OnPropertyChanged; } } } }