From fc76076c8a0518c34d0f5c19e619d05330b7db84 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 25 Sep 2015 20:37:14 +0100 Subject: [PATCH 1/3] Added implementation of Watermark for Textbox. --- samples/TestApplication/Program.cs | 6 ++-- src/Perspex.Controls/TextBox.cs | 9 +++++ src/Perspex.Themes.Default/TextBoxStyle.cs | 38 +++++++++++++++------- 3 files changed, 40 insertions(+), 13 deletions(-) diff --git a/samples/TestApplication/Program.cs b/samples/TestApplication/Program.cs index bfbb8a17ce..33db018363 100644 --- a/samples/TestApplication/Program.cs +++ b/samples/TestApplication/Program.cs @@ -340,8 +340,10 @@ namespace TestApplication Foreground = SolidColorBrush.Parse("#727272"), Margin = new Thickness(0, 0, 0, 10) }, - new TextBox { Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", Width = 200 }, - new TextBox { AcceptsReturn = true, TextWrapping = TextWrapping.Wrap, Width = 200, Height = 150, Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est." }, + + new TextBox { Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", Width = 200}, + new TextBox { Width = 200, Watermark="Watermark"}, + new TextBox { AcceptsReturn = true, TextWrapping = TextWrapping.Wrap, Width = 200, Height = 150, Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est." }, new TextBlock { Margin = new Thickness(0, 40, 0, 0), diff --git a/src/Perspex.Controls/TextBox.cs b/src/Perspex.Controls/TextBox.cs index ad48cc49af..a9c0f4d5f2 100644 --- a/src/Perspex.Controls/TextBox.cs +++ b/src/Perspex.Controls/TextBox.cs @@ -39,6 +39,9 @@ namespace Perspex.Controls public static readonly PerspexProperty TextWrappingProperty = TextBlock.TextWrappingProperty.AddOwner(); + public static readonly PerspexProperty WatermarkProperty = + PerspexProperty.Register("Watermark"); + private TextPresenter _presenter; static TextBox() @@ -101,6 +104,12 @@ namespace Perspex.Controls set { SetValue(TextProperty, value); } } + public string Watermark + { + get { return GetValue(WatermarkProperty); } + set { SetValue(WatermarkProperty, value); } + } + public TextWrapping TextWrapping { get { return GetValue(TextWrappingProperty); } diff --git a/src/Perspex.Themes.Default/TextBoxStyle.cs b/src/Perspex.Themes.Default/TextBoxStyle.cs index 3b3bfca452..0df99a14ea 100644 --- a/src/Perspex.Themes.Default/TextBoxStyle.cs +++ b/src/Perspex.Themes.Default/TextBoxStyle.cs @@ -8,6 +8,7 @@ using Perspex.Controls.Primitives; using Perspex.Controls.Templates; using Perspex.Media; using Perspex.Styling; +using System.Reactive.Linq; namespace Perspex.Themes.Default { @@ -58,19 +59,34 @@ namespace Perspex.Themes.Default [~Border.BackgroundProperty] = control[~TemplatedControl.BackgroundProperty], [~Border.BorderBrushProperty] = control[~TemplatedControl.BorderBrushProperty], [~Border.BorderThicknessProperty] = control[~TemplatedControl.BorderThicknessProperty], - Child = new ScrollViewer + + Child = new Panel { - [~ScrollViewer.CanScrollHorizontallyProperty] = control[~ScrollViewer.CanScrollHorizontallyProperty], - [~ScrollViewer.HorizontalScrollBarVisibilityProperty] = control[~ScrollViewer.HorizontalScrollBarVisibilityProperty], - [~ScrollViewer.VerticalScrollBarVisibilityProperty] = control[~ScrollViewer.VerticalScrollBarVisibilityProperty], - Content = new TextPresenter + Children = new Controls.Controls { - 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], + new TextBlock + { + Name="waterMark", + Opacity=0.5, + [~TextBlock.TextProperty] = control[~TextBox.WatermarkProperty], + [~TextBlock.IsVisibleProperty] = control[~TextBox.TextProperty].Cast().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], + } + } } } }; From 7964321dd1bee273e812cd9eb9a3e2d3939a46c6 Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 25 Sep 2015 21:31:08 +0100 Subject: [PATCH 2/3] Implemented UseFloatingWaterMark property. --- samples/TestApplication/Program.cs | 2 + src/Perspex.Controls/TextBox.cs | 9 ++++ src/Perspex.Themes.Default/TextBoxStyle.cs | 49 ++++++++++++++-------- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/samples/TestApplication/Program.cs b/samples/TestApplication/Program.cs index 33db018363..023235ea71 100644 --- a/samples/TestApplication/Program.cs +++ b/samples/TestApplication/Program.cs @@ -343,6 +343,8 @@ namespace TestApplication new TextBox { Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", Width = 200}, new TextBox { Width = 200, Watermark="Watermark"}, + new TextBox { Width = 200, Watermark="Floating Watermark", UseFloatingWatermark = true }, + new TextBox { Width = 200, Text="Lorem ipsum", ClearTextButton=true, Watermark="Watermark"}, new TextBox { AcceptsReturn = true, TextWrapping = TextWrapping.Wrap, Width = 200, Height = 150, Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est." }, new TextBlock { diff --git a/src/Perspex.Controls/TextBox.cs b/src/Perspex.Controls/TextBox.cs index a9c0f4d5f2..2d00e50814 100644 --- a/src/Perspex.Controls/TextBox.cs +++ b/src/Perspex.Controls/TextBox.cs @@ -42,6 +42,9 @@ namespace Perspex.Controls public static readonly PerspexProperty WatermarkProperty = PerspexProperty.Register("Watermark"); + public static readonly PerspexProperty UseFloatingWatermarkProperty = + PerspexProperty.Register("UseFloatingWatermark"); + private TextPresenter _presenter; static TextBox() @@ -110,6 +113,12 @@ namespace Perspex.Controls set { SetValue(WatermarkProperty, value); } } + public bool UseFloatingWatermark + { + get { return GetValue(UseFloatingWatermarkProperty); } + set { SetValue(UseFloatingWatermarkProperty, value); } + } + public TextWrapping TextWrapping { get { return GetValue(TextWrappingProperty); } diff --git a/src/Perspex.Themes.Default/TextBoxStyle.cs b/src/Perspex.Themes.Default/TextBoxStyle.cs index 0df99a14ea..7f72c68c3f 100644 --- a/src/Perspex.Themes.Default/TextBoxStyle.cs +++ b/src/Perspex.Themes.Default/TextBoxStyle.cs @@ -60,35 +60,48 @@ namespace Perspex.Themes.Default [~Border.BorderBrushProperty] = control[~TemplatedControl.BorderBrushProperty], [~Border.BorderThicknessProperty] = control[~TemplatedControl.BorderThicknessProperty], - Child = new Panel + Child = new StackPanel { Children = new Controls.Controls { new TextBlock { - Name="waterMark", - Opacity=0.5, + Name = "floatingWatermark", + Foreground = SolidColorBrush.Parse("#007ACC"), + FontSize = 10, [~TextBlock.TextProperty] = control[~TextBox.WatermarkProperty], - [~TextBlock.IsVisibleProperty] = control[~TextBox.TextProperty].Cast().Select(x => (object)string.IsNullOrEmpty(x)) + [~TextBlock.IsVisibleProperty] = control[~TextBox.TextProperty].Cast().Select(x => (object)(!string.IsNullOrEmpty(x) && control.UseFloatingWatermark)) }, - - new ScrollViewer + new Panel { - [~ScrollViewer.CanScrollHorizontallyProperty] = control[~ScrollViewer.CanScrollHorizontallyProperty], - [~ScrollViewer.HorizontalScrollBarVisibilityProperty] = control[~ScrollViewer.HorizontalScrollBarVisibilityProperty], - [~ScrollViewer.VerticalScrollBarVisibilityProperty] = control[~ScrollViewer.VerticalScrollBarVisibilityProperty], - Content = new TextPresenter + Children = new Controls.Controls { - 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], + new TextBlock + { + Name = "watermark", + Opacity = 0.5, + [~TextBlock.TextProperty] = control[~TextBox.WatermarkProperty], + [~TextBlock.IsVisibleProperty] = control[~TextBox.TextProperty].Cast().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; From 362f7e78c0bd79fe695288e6865947772f4df98a Mon Sep 17 00:00:00 2001 From: Dan Walmsley Date: Fri, 25 Sep 2015 21:32:21 +0100 Subject: [PATCH 3/3] implemented UseFloatingWatermark --- samples/TestApplication/Program.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/samples/TestApplication/Program.cs b/samples/TestApplication/Program.cs index 023235ea71..3056ef14f6 100644 --- a/samples/TestApplication/Program.cs +++ b/samples/TestApplication/Program.cs @@ -344,7 +344,6 @@ namespace TestApplication new TextBox { Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit.", Width = 200}, new TextBox { Width = 200, Watermark="Watermark"}, new TextBox { Width = 200, Watermark="Floating Watermark", UseFloatingWatermark = true }, - new TextBox { Width = 200, Text="Lorem ipsum", ClearTextButton=true, Watermark="Watermark"}, new TextBox { AcceptsReturn = true, TextWrapping = TextWrapping.Wrap, Width = 200, Height = 150, Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus magna. Cras in mi at felis aliquet congue. Ut a est eget ligula molestie gravida. Curabitur massa. Donec eleifend, libero at sagittis mollis, tellus est malesuada tellus, at luctus turpis elit sit amet quam. Vivamus pretium ornare est." }, new TextBlock {