Browse Source

Implemented UseFloatingWaterMark property.

Dan Walmsley 10 years ago
parent
commit
7964321dd1

+ 2 - 0
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
 							{

+ 9 - 0
src/Perspex.Controls/TextBox.cs

@@ -42,6 +42,9 @@ namespace Perspex.Controls
         public static readonly PerspexProperty<string> WatermarkProperty =
             PerspexProperty.Register<TextBox, string>("Watermark");
 
+        public static readonly PerspexProperty<bool> UseFloatingWatermarkProperty =
+            PerspexProperty.Register<TextBox, bool>("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); }

+ 31 - 18
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<string>().Select(x => (object)string.IsNullOrEmpty(x))
+                            [~TextBlock.IsVisibleProperty] = control[~TextBox.TextProperty].Cast<string>().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<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;