Example #1
0
        public PropertyBinding(
            BindingType bindingType,
            [NotNull] IDependencyProperty <TTarget> target,
            [NotNull] INotifyingObject <TSource> source,
            [NotNull] ValueConverter <TSource, TTarget> converter)
        {
            if (target == null)
            {
                throw new ArgumentNullException("target");
            }
            if (source == null)
            {
                throw new ArgumentNullException("source");
            }
            if (converter == null)
            {
                throw new ArgumentNullException("converter");
            }

            _target    = target;
            _source    = source;
            _converter = converter;

            switch (bindingType)
            {
            case BindingType.OneWay:
                _source.PropertyChanged += SourceOnPropertyChanged;
                SetTarget(_source.GetValue());
                break;

            case BindingType.TwoWay:
                _source.PropertyChanged += SourceOnPropertyChanged;
                _target.PropertyChanged += TargetOnPropertyChanged;
                SetTarget(_source.GetValue());
                SetSource(_target.GetValue());
                break;

            case BindingType.OneWayToSource:
                _target.PropertyChanged += TargetOnPropertyChanged;
                SetSource(_target.GetValue());
                break;

            default:
                throw new NotSupportedException(string.Format(
                                                    "The binding type '{0}' is not supported.",
                                                    bindingType));
            }
        }