// // Implementation // #region public void BindValue(object sender, PDFDataBindEventArgs args) /// <summary> /// Provides a method that can be added to the databind or databound event handlers, /// and will be called when that component or style is databound. /// </summary> /// <param name="sender">The sender of the event (must be a Style or an IPDFStyledComponent</param> /// <param name="args">The databind args with the context for creating the expression</param> /// <remarks> /// This method must be called before the Expression will be used, so the Expression can be built. /// If it is not called then the instance will fallback to the default base implementation /// </remarks> public void BindValue(object sender, PDFDataBindEventArgs args) { Style style; if (sender is Style) { style = (sender as Style); } else if (sender is IPDFStyledComponent) { style = (sender as IPDFStyledComponent).Style; } else { throw new InvalidCastException("Style values can only be bound on styles or the StyledComponents that own them"); } var context = args.Context; if (null == _expression) { _expression = CreateExpression(context); _variableProvider = context.Items.ValueProvider(context.CurrentIndex, context.DataStack.HasData ? context.DataStack.Current : null); } //Execute once to make sure we are all set up - although css variables may not be there. base.SetValue(this.EvaluateExpression(style)); }
/// <summary> /// Creates a new style value expression for the style key with the expression and an optional convertor and base value /// </summary> /// <param name="key">The style key this expression is assigned for</param> /// <param name="expressionString">The exppresion to be evaluated at runtime</param> /// <param name="convertor">An otpional convertor to make the result the required type</param> /// <param name="baseValue">An optional base value that will be returned before the expression is bound</param> public StyleValueExpression(PDFStyleKey <T> key, string expressionString, StyleValueConvertor <T> convertor, T baseValue) : base(key, baseValue) { this._expressionString = expressionString ?? throw new ArgumentNullException(nameof(expressionString)); this._convertor = convertor; this._variableProvider = null; this._expression = null; }