public void VisualStateGroupsFromSettersAreDistinct() { var x = new Setter(); x.Property = VisualStateManager.VisualStateGroupsProperty; x.Value = CreateTestStateGroups(); var label1 = new Label(); var label2 = new Label(); x.Apply(label1); x.Apply(label2); var groups1 = VisualStateManager.GetVisualStateGroups(label1); var groups2 = VisualStateManager.GetVisualStateGroups(label2); Assert.NotNull(groups1); Assert.NotNull(groups2); Assert.AreNotSame(groups1, groups2); Assert.That(groups1[0].CurrentState.Name, Is.EqualTo(NormalStateName)); Assert.That(groups2[0].CurrentState.Name, Is.EqualTo(NormalStateName)); VisualStateManager.GoToState(label1, InvalidStateName); Assert.That(groups1[0].CurrentState.Name, Is.EqualTo(InvalidStateName)); Assert.That(groups2[0].CurrentState.Name, Is.EqualTo(NormalStateName)); }
public void VisualElementGoesToCorrectStateWhenAvailableFromSetter() { double targetBottomMargin = 1.5; var group = new VisualStateGroup(); var list = new VisualStateGroupList(); var normalState = new VisualState { Name = NormalStateName }; normalState.Setters.Add(new Setter { Property = View.MarginBottomProperty, Value = targetBottomMargin }); var x = new Setter { Property = VisualStateManager.VisualStateGroupsProperty, Value = list }; list.Add(group); group.States.Add(normalState); var label1 = new Label(); var label2 = new Label(); x.Apply(label1); x.Apply(label2); Assert.That(label1.Margin.Bottom, Is.EqualTo(targetBottomMargin)); Assert.That(label2.Margin.Bottom, Is.EqualTo(targetBottomMargin)); }
public void Setter_With_TwoWay_Binding_And_Activator_Should_Update_Source() { using (UnitTestApplication.Start(TestServices.MockThreadingInterface)) { var data = new Data { Foo = "foo", }; var control = new TextBox { DataContext = data, }; var setter = new Setter { Property = TextBox.TextProperty, Value = new Binding { Path = "Foo", Mode = BindingMode.TwoWay } }; var activator = Observable.Never <bool>().StartWith(true); setter.Apply(null, control, activator); Assert.Equal("foo", control.Text); control.Text = "bar"; Assert.Equal("bar", data.Foo); } }
public void ApplyTest2() { tlog.Debug(tag, $"ApplyTest2 START"); Setter t2 = new Setter(); Assert.IsNotNull(t2, "null Setter"); Assert.Throws <ArgumentNullException>(() => t2.Apply(null)); Assert.Throws <ArgumentNullException>(() => t2.UnApply(null)); tlog.Debug(tag, $"ApplyTest2 END"); }
public void Materializes_Template_Should_Be_NameScope() { var control = new Decorator(); var template = new FuncTemplate <Canvas>(() => new Canvas()); var style = Mock.Of <IStyle>(); var setter = new Setter(Decorator.ChildProperty, template); setter.Apply(style, control, null); Assert.NotNull(NameScope.GetNameScope((Control)control.Child)); }
public void Materializes_Template_Should_Be_NameScope() { var control = new Decorator(); var template = new FuncTemplate<Canvas>(() => new Canvas()); var style = Mock.Of<IStyle>(); var setter = new Setter(Decorator.ChildProperty, template); setter.Apply(style, control, null); Assert.NotNull(NameScope.GetNameScope((Control)control.Child)); }
public void Setter_Should_Materialize_Template_To_Property() { var control = new Decorator(); var template = new FuncTemplate<Canvas>(() => new Canvas()); var style = Mock.Of<IStyle>(); var setter = new Setter(Decorator.ChildProperty, template); setter.Apply(style, control, null); Assert.IsType<Canvas>(control.Child); }
public void Setter_Should_Materialize_Template_To_Property() { var control = new Decorator(); var template = new FuncTemplate <Canvas>(() => new Canvas()); var style = Mock.Of <IStyle>(); var setter = new Setter(Decorator.ChildProperty, template); setter.Apply(style, control, null); Assert.IsType <Canvas>(control.Child); }
public void Setter_Should_Apply_Binding_To_Property() { var control = new TextBlock(); var subject = new BehaviorSubject <object>("foo"); var binding = Mock.Of <IBinding>(x => x.CreateSubject(control, TextBlock.TextProperty) == subject); var style = Mock.Of <IStyle>(); var setter = new Setter(TextBlock.TextProperty, binding); setter.Apply(style, control, null); Assert.Equal("foo", control.Text); }
public void Setter_Should_Apply_Value_Without_Activator_With_Style_Priority() { var control = new Mock <IStyleable>(); var style = Mock.Of <Style>(); var setter = new Setter(TextBlock.TextProperty, "foo"); setter.Apply(style, control.Object, null); control.Verify(x => x.Bind( TextBlock.TextProperty, It.IsAny <IObservable <BindingValue <string> > >())); }
public void Setter_Should_Apply_Binding_To_Property() { var control = new TextBlock(); var subject = new BehaviorSubject<object>("foo"); var binding = Mock.Of<IBinding>(x => x.CreateSubject(control, TextBlock.TextProperty) == subject); var style = Mock.Of<IStyle>(); var setter = new Setter(TextBlock.TextProperty, binding); setter.Apply(style, control, null); Assert.Equal("foo", control.Text); }
public void Setter_Should_Apply_Binding_Without_Activator_With_Style_Priority() { var control = new Mock <IStyleable>(); var style = Mock.Of <Style>(); var setter = new Setter(TextBlock.TextProperty, CreateMockBinding(TextBlock.TextProperty)); setter.Apply(style, control.Object, null); control.Verify(x => x.Bind( TextBlock.TextProperty, It.IsAny <IObservable <object> >(), BindingPriority.Style)); }
public void Setter_Should_Apply_Binding_To_Property() { var control = new TextBlock(); var subject = new BehaviorSubject<object>("foo"); var descriptor = new InstancedBinding(subject); var binding = Mock.Of<IBinding>(x => x.Initiate(control, TextBlock.TextProperty, null, false) == descriptor); var style = Mock.Of<IStyle>(); var setter = new Setter(TextBlock.TextProperty, binding); setter.Apply(style, control, null); Assert.Equal("foo", control.Text); }
public void Setter_Should_Apply_Binding_With_Activator_With_StyleTrigger_Priority() { var control = new Mock <IStyleable>(); var style = Mock.Of <Style>(); var setter = new Setter(TextBlock.TextProperty, CreateMockBinding(TextBlock.TextProperty)); var activator = new Subject <bool>(); setter.Apply(style, control.Object, activator); control.Verify(x => x.Bind( TextBlock.TextProperty, It.IsAny <IObservable <BindingValue <string> > >())); }
public void Setter_Should_Apply_Binding_To_Property() { var control = new TextBlock(); var subject = new BehaviorSubject <object>("foo"); var descriptor = InstancedBinding.OneWay(subject); var binding = Mock.Of <IBinding>(x => x.Initiate(control, TextBlock.TextProperty, null, false) == descriptor); var style = Mock.Of <IStyle>(); var setter = new Setter(TextBlock.TextProperty, binding); setter.Apply(style, control, null); Assert.Equal("foo", control.Text); }
public void Setter_Should_Apply_Value_With_Activator_With_StyleTrigger_Priority() { var control = new Mock <IStyleable>(); var style = Mock.Of <Style>(); var setter = new Setter(TextBlock.TextProperty, "foo"); var activator = new Subject <bool>(); setter.Apply(style, control.Object, activator); control.Verify(x => x.Bind( TextBlock.TextProperty, It.IsAny <IObservable <object> >(), BindingPriority.StyleTrigger)); }
public void ApplyTest1() { tlog.Debug(tag, $"ApplyTest1 START"); try { Setter t2 = new Setter(); Assert.IsNotNull(t2, "null Setter"); View view = new View(); t2.Apply(view); t2.UnApply(view); t2.Property = View.NameProperty; t2.Apply(view); t2.UnApply(view); view.Name = "View1"; t2.Apply(view); t2.UnApply(view); Assert.True(true, "Should go here"); } catch (Exception e) { Assert.Fail("Caught Exception" + e.ToString()); } tlog.Debug(tag, $"ApplyTest1 END"); }
public void Does_Not_Call_Converter_ConvertBack_On_OneWay_Binding() { var control = new Decorator { Name = "foo" }; var style = Mock.Of <IStyle>(); var binding = new Binding("Name", BindingMode.OneWay) { Converter = new TestConverter(), RelativeSource = new RelativeSource(RelativeSourceMode.Self), }; var setter = new Setter(Decorator.TagProperty, binding); var activator = new BehaviorSubject <bool>(true); setter.Apply(style, control, activator); Assert.Equal("foobar", control.Tag); // Issue #1218 caused TestConverter.ConvertBack to throw here. activator.OnNext(false); Assert.Null(control.Tag); }
public void Setter_With_TwoWay_Binding_And_Activator_Should_Update_Source() { using (PerspexLocator.EnterScope()) { PerspexLocator.CurrentMutable .Bind <IPlatformThreadingInterface>() .ToConstant(Mock.Of <IPlatformThreadingInterface>(x => x.CurrentThreadIsLoopThread == true)); var data = new Data { Foo = "foo", }; var control = new TextBox { DataContext = data, }; var setter = new Setter { Property = TextBox.TextProperty, Value = new Binding { Path = "Foo", Mode = BindingMode.TwoWay } }; var activator = Observable.Never <bool>().StartWith(true); setter.Apply(null, control, activator); Assert.Equal("foo", control.Text); control.Text = "bar"; Assert.Equal("bar", data.Foo); } }