Example #1
0
        private InstancedBinding Clone(InstancedBinding sourceInstance, IStyle style, IObservable <bool> activator)
        {
            if (activator != null)
            {
                var description = style?.ToString();

                switch (sourceInstance.Mode)
                {
                case BindingMode.OneTime:
                    if (sourceInstance.Observable != null)
                    {
                        var activated = new ActivatedObservable(activator, sourceInstance.Observable, description);
                        return(InstancedBinding.OneTime(activated, BindingPriority.StyleTrigger));
                    }
                    else
                    {
                        var activated = new ActivatedValue(activator, sourceInstance.Value, description);
                        return(InstancedBinding.OneTime(activated, BindingPriority.StyleTrigger));
                    }

                case BindingMode.OneWay:
                {
                    var activated = new ActivatedObservable(activator, sourceInstance.Observable, description);
                    return(InstancedBinding.OneWay(activated, BindingPriority.StyleTrigger));
                }

                case BindingMode.OneWayToSource:
                {
                    var activated = new ActivatedSubject(activator, sourceInstance.Subject, description);
                    return(InstancedBinding.OneWayToSource(activated, BindingPriority.StyleTrigger));
                }

                case BindingMode.TwoWay:
                {
                    var activated = new ActivatedSubject(activator, sourceInstance.Subject, description);
                    return(InstancedBinding.TwoWay(activated, BindingPriority.StyleTrigger));
                }

                default:
                    throw new NotSupportedException("Unsupported BindingMode.");
                }
            }
            else
            {
                return(sourceInstance.WithPriority(BindingPriority.Style));
            }
        }
Example #2
0
        private InstancedBinding Clone(InstancedBinding sourceInstance, IStyle style, IObservable <bool> activator)
        {
            InstancedBinding cloned;

            if (activator != null)
            {
                var description = style?.ToString();

                if (sourceInstance.Mode == BindingMode.TwoWay || sourceInstance.Mode == BindingMode.OneWayToSource)
                {
                    var activated = new ActivatedSubject(activator, sourceInstance.Subject, description);
                    cloned = new InstancedBinding(activated, sourceInstance.Mode, BindingPriority.StyleTrigger);
                }
                else if (sourceInstance.Mode == BindingMode.OneTime)
                {
                    var activated = new ActivatedValue(activator, sourceInstance.Value, description);
                    cloned = new InstancedBinding(activated, BindingMode.OneWay, BindingPriority.StyleTrigger);
                }
                else
                {
                    var activated = new ActivatedObservable(activator, sourceInstance.Observable ?? sourceInstance.Subject, description);
                    cloned = new InstancedBinding(activated, sourceInstance.Mode, BindingPriority.StyleTrigger);
                }
            }
            else
            {
                if (sourceInstance.Subject != null)
                {
                    cloned = new InstancedBinding(sourceInstance.Subject, sourceInstance.Mode, BindingPriority.Style);
                }
                else if (sourceInstance.Observable != null)
                {
                    cloned = new InstancedBinding(sourceInstance.Observable, sourceInstance.Mode, BindingPriority.Style);
                }
                else
                {
                    cloned = new InstancedBinding(sourceInstance.Value, BindingPriority.Style);
                }
            }

            return(cloned);
        }