/// <inheritdoc /> public void Dispose() { _disposed = true; Registration.DataBinding = null; DataBindingMode?.Dispose(); }
/// <summary> /// Gets the current value of the data binding /// </summary> /// <param name="baseValue">The base value of the property the data binding is applied to</param> /// <returns></returns> public TProperty GetValue(TProperty baseValue) { if (_disposed) { throw new ObjectDisposedException("DataBinding"); } if (Converter == null || DataBindingMode == null) { return(baseValue); } TProperty value = DataBindingMode.GetValue(baseValue); // If no easing is to be applied simple return whatever the current value is if (EasingTime == TimeSpan.Zero || !Converter.SupportsInterpolate) { return(value); } // If the value changed, update the current and previous values used for easing if (!Equals(value, _currentValue)) { ResetEasing(value); } // Apply interpolation between the previous and current value return(GetInterpolatedValue()); }
public static DataBindingInfo Create(DataBindingMode mode, string bindingContext) { return(new DataBindingInfo { BindingMode = mode, BindingContext = bindingContext, }); }
protected ClientBoundUIHintAttribute(DataBindingAttributeDictionary dataBindingAttributeDictionary, DataBindingMode validForModes, string uiHint) : base(uiHint) { if (dataBindingAttributeDictionary == null) { throw new ArgumentNullException("dataBindingAttributeDictionary"); } DataBindingAttributeDictionary = dataBindingAttributeDictionary; _validForModes = validForModes; }
public static string ClientDataBindingModeString(DataBindingMode mode) { switch (mode) { case DataBindingMode.Editable: return("value"); case DataBindingMode.Readonly: return("text"); default: throw new NotSupportedException(string.Format("The ClientDataBindingMode '{0}' is not supported.", mode)); } }
/// <summary> /// Releases the unmanaged resources used by the object and optionally releases the managed resources. /// </summary> /// <param name="disposing"> /// <see langword="true" /> to release both managed and unmanaged resources; /// <see langword="false" /> to release only unmanaged resources. /// </param> protected virtual void Dispose(bool disposing) { if (disposing) { _disposed = true; if (Registration != null) { Registration.DataBinding = null; } DataBindingMode?.Dispose(); } }
public void SetMode(DataBindingMode mode, bool force) { if (force) { this.Mode = mode; } else { if (this.Mode == DataBindingMode.StickyDetails) { return; } this.Mode = mode; } }
private void ApplyDataBindingMode() { DataBindingMode?.Dispose(); DataBindingMode = null; switch (Entity.DataBindingMode) { case DirectDataBindingEntity directDataBindingEntity: DataBindingMode = new DirectDataBinding <TLayerProperty, TProperty>(this, directDataBindingEntity); break; case ConditionalDataBindingEntity conditionalDataBindingEntity: DataBindingMode = new ConditionalDataBinding <TLayerProperty, TProperty>(this, conditionalDataBindingEntity); break; } }
/// <inheritdoc /> public void Save() { if (_disposed) { throw new ObjectDisposedException("DataBinding"); } if (!LayerProperty.Entity.DataBindingEntities.Contains(Entity)) { LayerProperty.Entity.DataBindingEntities.Add(Entity); } // General Entity.TargetExpression = Registration.PropertyExpression.ToString(); Entity.EasingTime = EasingTime; Entity.EasingFunction = (int)EasingFunction; DataBindingMode?.Save(); }
public SimpleClientBoundExtensionAttribute(string attributeName, string extensionValue, DataBindingMode validForModes) { if (attributeName == null) { throw new ArgumentNullException("attributeName"); } _attributeName = attributeName; if (extensionValue == null) { throw new ArgumentNullException("extensionValue"); } _extensionValue = extensionValue; if (validForModes == null) { throw new ArgumentNullException("validForModes"); } _validForModes = validForModes; }
/// <inheritdoc /> public void Load() { if (_disposed) { throw new ObjectDisposedException("DataBinding"); } // General DataBindingRegistration <TLayerProperty, TProperty> registration = LayerProperty.GetDataBindingRegistration <TProperty>(Entity.TargetExpression); if (registration != null) { ApplyRegistration(registration); } EasingTime = Entity.EasingTime; EasingFunction = (Easings.Functions)Entity.EasingFunction; DataBindingMode?.Load(); }
public override DataBindingAttributeDictionary ApplyExtension(DataBindingAttributeDictionary bindings, DataBindingMode currentMode) { if (!_validForModes.HasFlag(currentMode) || !bindings.Any(b => b.Key == _attributeName)) { return(bindings); } var valueBinding = bindings.First(b => b.Key == _attributeName); var extendedValueBinding = BuildExtensionString(valueBinding.Value.ToString()); bindings.SetAttribute(valueBinding.Key, extendedValueBinding); return(bindings); }
public bool IsValidForContext <TModel, TValue>(DataBindingMode mode, Expression <Func <TModel, TValue> > expression) { return(typeof(TValue) == typeof(DateTime) || typeof(TValue) == typeof(DateTime?)); }
public ClientBoundMultiProperty(string attributes, DataBindingMode validForModes = DataBindingMode.Readonly | DataBindingMode.Editable, string templateName = "") : base(BuildDataBindingAttributeDictionary(attributes), validForModes, templateName) { }
public DragDropToken() { this.originalMode = DataBindingModeModel.Instance.Mode; DataBindingDragDropManager.Reset(); }
private static DataBindingAttributeDictionary GetClientSideDataBindingAttributesFor <TModel, TValue>(DataBindingAttributeDictionary dataBindingAttributes, Expression <Func <TModel, TValue> > expression, DataBindingMode mode) { if (dataBindingAttributes == null) { throw new ArgumentNullException("dataBindingAttributes"); } //var dataBindingAttributes = new DataBindingAttributeDictionary(); if (expression.Body.NodeType == ExpressionType.MemberAccess) { var member = ((MemberExpression)expression.Body).Member; if (member.MemberType != MemberTypes.Property) { throw new NotSupportedException("The expression's return type must be a Property type."); } foreach (var bindingAttribute in member.GetCustomAttributes <ClientBoundUIHintAttribute>().Where(a => a.IsValidForMode(mode))) { if (!bindingAttribute.IsValidForProperty(member)) { throw new ArgumentException( String.Format( "The ClientBoundUIHintAttribute, '{0}' does not support binding to the property '{1}' which is of type '{2}' and is a member of '{3}.", bindingAttribute.GetType().FullName, member.Name, member.ReflectedType.FullName, typeof(TModel).FullName)); } dataBindingAttributes.MergeAttributes(bindingAttribute.GetDatabindingAttributes()); } ApplyDataBindingExtensions(member, dataBindingAttributes, mode); } return(dataBindingAttributes); }
/// <summary> /// Constructs a DataBindingAttributeDictionary consisting of all data binding attributes for supplied expression. /// </summary> /// <typeparam name="TModel"></typeparam> /// <typeparam name="TValue"></typeparam> /// <param name="expression">An expression indicating the property for which the build the DataBindingAttributeDictionary.</param> /// <param name="viewData"></param> /// <param name="mode"></param> /// <param name="bindingLevel"></param> /// <returns></returns> public DataBindingAttributeDictionary BuildDataBindingAttributesFor <TModel, TValue>(Expression <Func <TModel, TValue> > expression, ViewDataDictionary <TModel> viewData, DataBindingMode mode, ClientBindingLevel bindingLevel) { var dataBindingAttributes = new DataBindingAttributeDictionary(); var dataBindingInfoFactory = new DataBindingInfoFactory(); var bindingInfo = dataBindingInfoFactory.CreateDataBindingAttributeInfoFor(expression, mode, bindingLevel); dataBindingAttributes.MergeAttribute(bindingInfo); //GetClientSideDataBindingAttributesFor(dataBindingAttributes, expression, mode); GetClientSideDataBindingAttributesFor(dataBindingAttributes, expression, mode); //dataBindingAttributes.MergeAttributes(clientSideDataBindingAttributes); return(dataBindingAttributes); }
public bool IsValidForMode(DataBindingMode currentMode) { return(_validForModes.HasFlag(currentMode)); }
public NumericValueBindingExtensionAttribute(DataBindingMode validForModes) : base("value", "formattedNumber", validForModes) { }
public abstract DataBindingAttributeDictionary ApplyExtension(DataBindingAttributeDictionary bindings, DataBindingMode currentMode);
private static DataBindingAttributeDictionary ApplyDataBindingExtensions(MemberInfo property, DataBindingAttributeDictionary dataBindingAttributes, DataBindingMode mode) { foreach (var extensionAttribute in property.GetCustomAttributes <ClientBoundExtensionAttribute>()) { extensionAttribute.ApplyExtension(dataBindingAttributes, mode); } return(dataBindingAttributes); }
/// <summary> /// Constructs an anonymous object containing the data Knockout.JS binding property and all data binding attributes appropriate for the expression. /// </summary> /// <typeparam name="TModel"></typeparam> /// <typeparam name="TValue"></typeparam> /// <param name="expression"></param> /// <param name="viewData"></param> /// <param name="mode"></param> /// <param name="bindingLevel"></param> /// <param name="additionalViewData"></param> /// <returns></returns> public KnockoutDataBindingObject BuildHtmlAttributeObjectFor <TModel, TValue>(Expression <Func <TModel, TValue> > expression, ViewDataDictionary <TModel> viewData, DataBindingMode mode, ClientBindingLevel bindingLevel, object additionalViewData) { var dataBindingAttributes = BuildDataBindingAttributesFor(expression, viewData, mode, bindingLevel); return(dataBindingAttributes == null || !dataBindingAttributes.Any() ? null : new KnockoutDataBindingObject(dataBindingAttributes, additionalViewData)); }
public DataBindingInfo CreateDataBindingAttributeInfoFor <TModel, TValue>(Expression <Func <TModel, TValue> > expression, DataBindingMode mode, ClientBindingLevel bindingLevel) { if (typeof(TValue).IsComplexType()) { throw new NotSupportedException("Creation of data binding attributes is not supported for complex types."); } if (expression.Body.NodeType == ExpressionType.Parameter) { throw new ArgumentException("DataBindingAttributeInfo cannot be created from a self referencing Expression (such as m => m)."); } var bindingContext = _bindingContextHelper.BuildBindingContextFor(expression, bindingLevel); _customizations.Where(c => c.IsValidForContext(mode, expression)).ToList() .ForEach(c => bindingContext = c.ApplyCustomization(bindingContext)); var dataBindingInfo = DataBindingInfo.Create(mode, bindingContext); //todo: enable customization of DataBinding expression. Examples: click, hasFocus, valueUpdate return(dataBindingInfo); }