protected virtual BindingDescriptor CreateBindingDescriptor(BindingDescriptor source) { return(new BindingDescriptor { Mode = source.Mode, Priority = source.Priority, Property = source.Property, Source = this, }); }
/// <summary> /// Gets or sets a binding for a <see cref="PerspexProperty"/>. /// </summary> /// <param name="binding">The binding information.</param> public IObservable <object> this[BindingDescriptor binding] { get { return(new BindingDescriptor { Mode = binding.Mode, Priority = binding.Priority, Property = binding.Property, Source = this, }); } set { var mode = (binding.Mode == BindingMode.Default) ? binding.Property.DefaultBindingMode : binding.Mode; var sourceBinding = value as BindingDescriptor; if (sourceBinding == null && mode != BindingMode.OneWay) { throw new InvalidOperationException("Can only bind OneWay to plain IObservable."); } switch (mode) { case BindingMode.Default: case BindingMode.OneWay: Bind(binding.Property, value, binding.Priority); break; case BindingMode.OneTime: SetValue(binding.Property, sourceBinding.Source.GetValue(sourceBinding.Property), binding.Priority); break; case BindingMode.OneWayToSource: sourceBinding.Source.Bind(sourceBinding.Property, GetObservable(binding.Property), binding.Priority); break; case BindingMode.TwoWay: BindTwoWay(binding.Property, sourceBinding.Source, sourceBinding.Property); break; } } }
/// <summary> /// Gets or sets a binding for a <see cref="PerspexProperty"/>. /// </summary> /// <param name="binding">The binding information.</param> public IObservable <object> this[BindingDescriptor binding] { get { return(CreateBindingDescriptor(binding)); } set { var mode = (binding.Mode == BindingMode.Default) ? binding.Property.DefaultBindingMode : binding.Mode; var sourceBinding = value as BindingDescriptor; if (sourceBinding == null && mode > BindingMode.OneWay) { mode = BindingMode.OneWay; } switch (mode) { case BindingMode.Default: case BindingMode.OneWay: Bind(binding.Property, value, binding.Priority); break; case BindingMode.OneTime: SetValue(binding.Property, sourceBinding.Source.GetValue(sourceBinding.Property), binding.Priority); break; case BindingMode.OneWayToSource: sourceBinding.Source.Bind(sourceBinding.Property, GetObservable(binding.Property), binding.Priority); break; case BindingMode.TwoWay: BindTwoWay(binding.Property, sourceBinding.Source, sourceBinding.Property); break; } } }