public InstancedBinding Initiate( IAvaloniaObject target, AvaloniaProperty targetProperty, object anchor = null, bool enableDataValidation = false) { var mode = Mode == BindingMode.Default ? targetProperty.GetMetadata(target.GetType()).DefaultBindingMode : Mode; switch (mode) { case BindingMode.OneTime: return(InstancedBinding.OneTime(Source.GetObservable(Property))); case BindingMode.OneWay: return(InstancedBinding.OneWay(Source.GetObservable(Property))); case BindingMode.OneWayToSource: return(InstancedBinding.OneWayToSource(Source.GetSubject(Property))); case BindingMode.TwoWay: return(InstancedBinding.TwoWay(Source.GetSubject(Property))); default: throw new NotSupportedException("Unsupported BindingMode."); } }
/// <inheritdoc/> public InstancedBinding Initiate( IAvaloniaObject target, AvaloniaProperty targetProperty, object anchor = null, bool enableDataValidation = false) { if (Converter == null) { throw new NotSupportedException("MultiBinding without Converter not currently supported."); } var targetType = targetProperty?.PropertyType ?? typeof(object); var children = Bindings.Select(x => x.Initiate(target, null)); var input = children.Select(x => x.Subject).CombineLatest().Select(x => ConvertValue(x, targetType)); var mode = Mode == BindingMode.Default ? targetProperty.GetMetadata(target.GetType()).DefaultBindingMode : Mode; switch (mode) { case BindingMode.OneTime: return(InstancedBinding.OneTime(input, Priority)); case BindingMode.OneWay: return(InstancedBinding.OneWay(input, Priority)); default: throw new NotSupportedException( "MultiBinding currently only supports OneTime and OneWay BindingMode."); } }
/// <inheritdoc/> public InstancedBinding?Initiate( IAvaloniaObject target, AvaloniaProperty?targetProperty, object?anchor = null, bool enableDataValidation = false) { var targetType = targetProperty?.PropertyType ?? typeof(object); var converter = Converter; // We only respect `StringFormat` if the type of the property we're assigning to will // accept a string. Note that this is slightly different to WPF in that WPF only applies // `StringFormat` for target type `string` (not `object`). if (!string.IsNullOrWhiteSpace(StringFormat) && (targetType == typeof(string) || targetType == typeof(object))) { converter = new StringFormatMultiValueConverter(StringFormat !, converter); } var children = Bindings.Select(x => x.Initiate(target, null)); var input = children.Select(x => x?.Observable !) .Where(x => x is not null) .CombineLatest() .Select(x => ConvertValue(x, targetType, converter)) .Where(x => x != BindingOperations.DoNothing); var mode = Mode == BindingMode.Default ? targetProperty?.GetMetadata(target.GetType()).DefaultBindingMode : Mode; switch (mode) { case BindingMode.OneTime: return(InstancedBinding.OneTime(input, Priority)); case BindingMode.OneWay: return(InstancedBinding.OneWay(input, Priority)); default: throw new NotSupportedException( "MultiBinding currently only supports OneTime and OneWay BindingMode."); } }