internal override void SetUp(BindableObject bindable) { if (Binding != null) { bindable.SetBinding(_boundProperty, Binding.Clone()); //CLONE } }
public void Do() { BindableObject bindableObject = globalDataList.GatheredInstances[instanceIndex] as BindableObject; var property = globalDataList.GatheredBindableProperties[bindablePropertyIndex]; var value = globalDataList.GatheredInstances[valueIndex] as BindingBase; bindableObject?.SetBinding(property, value); }
public Binding ProvideValue(IServiceProvider serviceProvider) { if (string.IsNullOrWhiteSpace(StringFormat) && Converter == null) { throw new InvalidOperationException( $"{nameof(MultiBinding)} requires a {nameof(Converter)} or {nameof(StringFormat)}"); } SetProvideValue(serviceProvider); //Get the object that the markup extension is being applied to var provideValueTarget = (IProvideValueTarget)serviceProvider?.GetService(typeof(IProvideValueTarget)); _target = provideValueTarget?.TargetObject as BindableObject; if (_target == null) { return(null); } foreach (var b in Bindings) { if (b is Binding binding) { var property = BindableProperty.Create($"Property-{Guid.NewGuid():N}", typeof(object), typeof(MultiBinding), default(object), propertyChanged: (_, o, n) => SetValue()); _properties.Add(property); _target.SetBinding(property, binding); } else if (b is string str) { var property = BindableProperty.Create($"Property-{Guid.NewGuid():N}", typeof(string), typeof(MultiBinding), default(string), propertyChanged: (_, o, n) => SetValue()); _properties.Add(property); _target.SetValue(property, str); } else { throw new ArgumentException("MultiBinding can only accept string or Binding arguments \\n" + $"Impossible to accept a value of type {b.GetType().Name}"); } } SetValue(); var multibinding = new Binding { Path = nameof(InternalValue.Value), Converter = new MultiValueConverterWrapper(Converter, StringFormat), ConverterParameter = ConverterParameter, Source = _internalValue }; return(multibinding); }
public static T BindTo <T>(this T source, BindableObject target, BindableProperty sourceProperty, BindableProperty targetProperty, BindingMode mode = BindingMode.Default, IValueConverter converter = null, string stringFormat = null) where T : BindableObject { if (target.BindingContext != null && target?.BindingContext != source) { Console.WriteLine($"Incompatible binding source!(from source {source} to target {target.BindingContext})"); } target.BindingContext = source; target.SetBinding(targetProperty, sourceProperty.PropertyName, mode, converter, stringFormat); return(source); }
public static void SetUpBinding ( this BindableObject view, BindableProperty bindableProperty, string viewModelPropertyName, BindingMode bindingMode = BindingMode.OneWay, IValueConverter converter = null, object converterParameter = null, string stringFormat = null, object source = null ) { view.SetBinding(bindableProperty, new Binding(viewModelPropertyName, bindingMode, converter, converterParameter, stringFormat, source)); }
bool GetVariable(string argument, BindingBase argumentBinding, BindableObject targetElement) { if (argument == null || argumentBinding == null) { return(false); } var variableId = $"{argument}{variableCount++}"; VariableProperty = BindableProperty.Create("Variable", typeof(string), typeof(GraphQLExtension), default(string), propertyChanged: OnVariablePropertyChanged); targetElement.SetBinding(VariableProperty, argumentBinding); variableChangedHandler = new VariableChangeHandler { VariableId = variableId, VariableValue = (string)targetElement.GetValue(VariableProperty), }; return(true); }
static void SetValue(BindableObject bindable, Setter setter) { var binding = setter.Value as Binding; if (binding != null) { var prop = (BindableProperty)bindable.GetType() .GetField(setter.Property + "Property", BindablePropertyFlags) .GetValue(null); bindable.SetBinding(prop, new Binding(binding.Path, binding.Mode, binding.Converter, binding.ConverterParameter, binding.StringFormat)); return; } var pInfo = bindable.GetType().GetTypeInfo().GetRuntimeProperty(setter.Property); pInfo.SetMethod.Invoke(bindable, new[] { ConvertValue(pInfo, (string)setter.Value) }); }
public Binding ProvideValue(IServiceProvider serviceProvider) { try { if (string.IsNullOrWhiteSpace(StringFormat) && Converter == null) { throw new InvalidOperationException($"{nameof(MultiBinding)} requires a {nameof(Converter)} or {nameof(StringFormat)}"); } //Get the object that the markup extension is being applied to var provideValueTarget = (IProvideValueTarget)serviceProvider?.GetService(typeof(IProvideValueTarget)); _target = provideValueTarget?.TargetObject as BindableObject; if (_target == null) { return(null); } foreach (Binding b in Bindings) { var property = BindableProperty.Create($"Property-{Guid.NewGuid().ToString("N")}", typeof(object), typeof(MultiBinding), default(object), propertyChanged: (_, o, n) => SetValue()); _properties.Add(property); _target.SetBinding(property, b); } SetValue(); var binding = new Binding { Path = nameof(InternalValue.Value), Converter = new MultiValueConverterWrapper(Converter, StringFormat), ConverterParameter = ConverterParameter, Source = _internalValue, Mode = BindingMode.OneWay }; return(binding); } catch (Exception ex) { throw ex; } }
public static Binding BindProperty(BindableProperty p, BindableObject view, IEnumerable <PropertyInfo> modelProperties) { var pName = p.PropertyName; var pType = p.ReturnType; //var pBindingMode = p.DefaultBindingMode; var matchProp = modelProperties.FirstOrDefault(mp => mp.Name == pName && pType.GetTypeInfo().IsAssignableFrom(mp.PropertyType.GetTypeInfo())); if (matchProp == null) { return(null); } var binding = new Binding(pName, BindingMode.TwoWay); view.SetBinding(p, binding); return(binding); }
public static void SetCurrentValue(this BindableObject self, BindableProperty property, object value) { if (self == null) { throw new ArgumentNullException(nameof(self)); } if (property == null) { throw new ArgumentNullException(nameof(property)); } var backupBinding = self.GetBinding(property); //backup binding var backupConverter = backupBinding.Converter; //backup orig. converter self.SetValue(property, value); //removes the binding. backupBinding.Converter = new DefaultValueConverter { DefaultValue = value }; //change the converter self.SetBinding(property, backupBinding); //target should be updated to the default value var converterField = backupBinding.GetType().GetTypeInfo().GetDeclaredField("_converter"); converterField.SetValue(backupBinding, backupConverter); //restore the converter }
internal void Apply(BindableObject target, bool fromStyle = false) { if (target == null) { throw new ArgumentNullException("target"); } if (PropertyName == null) { return; } if (TargetReference != null) { target = TargetReference; } object originalValue = target.GetValue(Property); if (!Equals(originalValue, Property.DefaultValue)) { _originalValues.Remove(target); _originalValues.Add(target, originalValue); } var dynamicResource = Value as DynamicResource; var binding = Value as BindingBase; if (binding != null) { target.SetBinding(Property, binding.Clone()); //clone } //else if (dynamicResource != null) //target.SetDynamicResource(Property, dynamicResource.Key, fromStyle); else { target.SetValue(Property, Value); } }
/// <summary> /// Convenience helper, which enables you to bind any property /// of your View Model to an object you pass in. /// </summary> protected void BindToViewModel(BindableObject self, BindableProperty targetProperty, Expression <Func <TViewModel, object> > sourceProperty, BindingMode mode = BindingMode.Default, IValueConverter converter = null, string stringFormat = null) { self.SetBinding(targetProperty, sourceProperty, mode, converter, stringFormat); }
internal override void SetUp(BindableObject bindable) { if (Binding != null) bindable.SetBinding(_boundProperty, Binding.Clone()); }
public static void SetBinding <TModel, TProp, TDest>(this BindableObject self, BindableProperty targetProperty, Expression <Func <TModel, object> > sourceProperty, Func <TProp, TDest> converter) { self.SetBinding <TModel>(targetProperty, sourceProperty, BindingMode.OneWay, new FuncValueConverter <TProp, TDest>(converter)); }
public static void BindValue <TContext, TProperty>(this TContext context, BindableObject obj, BindableProperty property, Expression <Func <TContext, TProperty> > propertyAccessor) { obj.SetBinding(property, propertyAccessor.ToPropertyPathName()); }
public static BindableObject Binding(this BindableObject bindableObject, BindableProperty targetProperty, BindingBase binding) { bindableObject.SetBinding(targetProperty, binding); return(bindableObject); }