Example #1
0
        public async void Should_Produce_Value_On_Activator_True()
        {
            var activator = new BehaviorSubject<bool>(true);
            var target = new StyleBinding(activator, 1, string.Empty);
            var result = await target.Take(1);

            Assert.Equal(1, result);
        }
Example #2
0
        public async void Should_Produce_Value_On_Activator_True()
        {
            var activator = new BehaviorSubject <bool>(true);
            var target    = new StyleBinding(activator, 1, string.Empty);
            var result    = await target.Take(1);

            Assert.Equal(1, result);
        }
Example #3
0
        public async void Should_Produce_UnsetValue_On_Activator_False()
        {
            var activator = new BehaviorSubject<bool>(false);
            var target = new StyleBinding(activator, 1, string.Empty);
            var result = await target.Take(1);

            Assert.Equal(PerspexProperty.UnsetValue, result);
        }
Example #4
0
        public async void Should_Produce_UnsetValue_On_Activator_False()
        {
            var activator = new BehaviorSubject <bool>(false);
            var target    = new StyleBinding(activator, 1, string.Empty);
            var result    = await target.Take(1);

            Assert.Equal(PerspexProperty.UnsetValue, result);
        }
Example #5
0
        public void Should_Complete_When_Activator_Completes()
        {
            var activator = new BehaviorSubject<bool>(false);
            var target = new StyleBinding(activator, 1, string.Empty);
            var completed = false;

            target.Subscribe(_ => { }, () => completed = true);
            activator.OnCompleted();

            Assert.True(completed);
        }
Example #6
0
        public void Should_Complete_When_Activator_Completes()
        {
            var activator = new BehaviorSubject <bool>(false);
            var target    = new StyleBinding(activator, 1, string.Empty);
            var completed = false;

            target.Subscribe(_ => { }, () => completed = true);
            activator.OnCompleted();

            Assert.True(completed);
        }
Example #7
0
 /// <summary>
 /// Applies the setter to the control.
 /// </summary>
 /// <param name="style">The style that is being applied.</param>
 /// <param name="control">The control.</param>
 /// <param name="activator">An optional activator.</param>
 public void Apply(IStyle style, IStyleable control, IObservable<bool> activator)
 {
     if (activator == null)
     {
         control.Bind(Property, Source, BindingPriority.Style);
     }
     else
     {
         var binding = new StyleBinding(activator, Source, style.ToString());
         control.Bind(Property, binding, BindingPriority.StyleTrigger);
     }
 }
Example #8
0
        public void Should_Change_Value_On_Activator_Change()
        {
            var activator = new BehaviorSubject<bool>(false);
            var target = new StyleBinding(activator, 1, string.Empty);
            var result = new List<object>();

            target.Subscribe(x => result.Add(x));

            activator.OnNext(true);
            activator.OnNext(false);

            Assert.Equal(new[] { PerspexProperty.UnsetValue, 1, PerspexProperty.UnsetValue }, result);
        }
Example #9
0
        public void Should_Change_Value_On_Activator_Change()
        {
            var activator = new BehaviorSubject <bool>(false);
            var target    = new StyleBinding(activator, 1, string.Empty);
            var result    = new List <object>();

            target.Subscribe(x => result.Add(x));

            activator.OnNext(true);
            activator.OnNext(false);

            Assert.Equal(new[] { PerspexProperty.UnsetValue, 1, PerspexProperty.UnsetValue }, result);
        }
Example #10
0
        public void Attach(IStyleable control)
        {
            var description = "Style " + this.Selector.ToString();
            var match = this.Selector.Match(control);

            if (match.ImmediateResult.HasValue)
            {
                if (match.ImmediateResult == true)
                {
                    foreach (Setter setter in this.Setters)
                    {
                        if (setter.Source != null && setter.Value != null)
                        {
                            throw new InvalidOperationException("Cannot set both Source and Value on a Setter.");
                        }

                        if (setter.Source == null)
                        {
                            control.SetValue(setter.Property, setter.Value, BindingPriority.Style);
                        }
                        else
                        {
                            control.Bind(setter.Property, setter.Source, BindingPriority.Style);
                        }
                    }
                }
            }
            else
            {
                foreach (Setter setter in this.Setters)
                {
                    if (setter.Source != null && setter.Value != null)
                    {
                        throw new InvalidOperationException("Cannot set both Source and Value on a Setter.");
                    }

                    StyleBinding binding;

                    if (setter.Source == null)
                    {
                        binding = new StyleBinding(match.ObservableResult, setter.Value, description);
                    }
                    else
                    {
                        binding = new StyleBinding(match.ObservableResult, setter.Source, description);
                    }

                    control.Bind(setter.Property, binding, BindingPriority.StyleTrigger);
                }
            }
        }