Example #1
0
        /// <summary>
        /// The default template for the <see cref="TextBox"/> control.
        /// </summary>
        /// <param name="control">The control being styled.</param>
        /// <returns>The root of the instantiated template.</returns>
        public static Control Template(TextBox control)
        {
            Border result = new Border
            {
                Name = "border",
                Padding = new Thickness(2),
                [~Border.BackgroundProperty] = control[~TextBox.BackgroundProperty],
                [~Border.BorderBrushProperty] = control[~TextBox.BorderBrushProperty],
                [~Border.BorderThicknessProperty] = control[~TextBox.BorderThicknessProperty],
                Child = new ScrollViewer
                {
                    [~ScrollViewer.CanScrollHorizontallyProperty] = control[~ScrollViewer.CanScrollHorizontallyProperty],
                    [~ScrollViewer.HorizontalScrollBarVisibilityProperty] = control[~ScrollViewer.HorizontalScrollBarVisibilityProperty],
                    [~ScrollViewer.VerticalScrollBarVisibilityProperty] = control[~ScrollViewer.VerticalScrollBarVisibilityProperty],
                    Content = new TextPresenter
                    {
                        Name = "textPresenter",
                        [~TextPresenter.CaretIndexProperty] = control[~TextBox.CaretIndexProperty],
                        [~TextPresenter.SelectionStartProperty] = control[~TextBox.SelectionStartProperty],
                        [~TextPresenter.SelectionEndProperty] = control[~TextBox.SelectionEndProperty],
                        [~TextPresenter.TextProperty] = control[~TextBox.TextProperty],
                        [~TextPresenter.TextWrappingProperty] = control[~TextBox.TextWrappingProperty],
                    }
                }
            };

            return result;
        }
Example #2
0
        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);
            }
        }
Example #3
0
        /// <summary>
        /// The default template for the <see cref="TextBox"/> control.
        /// </summary>
        /// <param name="control">The control being styled.</param>
        /// <returns>The root of the instantiated template.</returns>
        public static Control Template(TextBox control)
        {
            Border result = new Border
            {
                Name = "border",
                Padding = new Thickness(2),
                [~Border.BackgroundProperty] = control[~TemplatedControl.BackgroundProperty],
                [~Border.BorderBrushProperty] = control[~TemplatedControl.BorderBrushProperty],
                [~Border.BorderThicknessProperty] = control[~TemplatedControl.BorderThicknessProperty],

                Child = new StackPanel
                {
                    Children = new Controls.Controls
                    {
                        new TextBlock
                        {
                            Name  = "floatingWatermark",
                            Foreground = SolidColorBrush.Parse("#007ACC"),
                            FontSize = 10,
                            [~TextBlock.TextProperty] = control[~TextBox.WatermarkProperty],
                            [~TextBlock.IsVisibleProperty] = control[~TextBox.TextProperty].Cast<string>().Select(x => (object)(!string.IsNullOrEmpty(x) && control.UseFloatingWatermark))
                        },
                        new Panel
                        {
                            Children = new Controls.Controls
                            {
                                new TextBlock
                                {
                                    Name = "watermark",
                                    Opacity = 0.5,
                                    [~TextBlock.TextProperty] = control[~TextBox.WatermarkProperty],
                                    [~TextBlock.IsVisibleProperty] = control[~TextBox.TextProperty].Cast<string>().Select(x => (object)string.IsNullOrEmpty(x))
                                },
                                new ScrollViewer
                                {
                                    [~ScrollViewer.CanScrollHorizontallyProperty] = control[~ScrollViewer.CanScrollHorizontallyProperty],
                                    [~ScrollViewer.HorizontalScrollBarVisibilityProperty] = control[~ScrollViewer.HorizontalScrollBarVisibilityProperty],
                                    [~ScrollViewer.VerticalScrollBarVisibilityProperty] = control[~ScrollViewer.VerticalScrollBarVisibilityProperty],
                                    Content = new TextPresenter
                                    {
                                        Name = "textPresenter",
                                        [~TextPresenter.CaretIndexProperty] = control[~TextBox.CaretIndexProperty],
                                        [~TextPresenter.SelectionStartProperty] = control[~TextBox.SelectionStartProperty],
                                        [~TextPresenter.SelectionEndProperty] = control[~TextBox.SelectionEndProperty],
                                        [~TextBlock.TextProperty] = control[~TextBox.TextProperty],
                                        [~TextBlock.TextWrappingProperty] = control[~TextBox.TextWrappingProperty],
                                    }
                                }
                            }
                        }                        
                    }
                },
            };

            return result;
        }
Example #4
0
        public void Setter_With_TwoWay_Binding_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
                    }
                };

                setter.Apply(null, control, null);
                Assert.Equal("foo", control.Text);

                control.Text = "bar";
                Assert.Equal("bar", data.Foo);
            }
        }