Browse Source

Merge branch 'master' of https://github.com/danwalmsley/Perspex into danwalmsley-master

pull/227/head
Steven Kirk 11 years ago
parent
commit
2c015bea36
  1. 7
      samples/TestApplication/Program.cs
  2. 18
      src/Perspex.Controls/TextBox.cs
  3. 53
      src/Perspex.Themes.Default/TextBoxStyle.cs

7
samples/TestApplication/Program.cs

@ -341,8 +341,11 @@ namespace TestApplication
Foreground = SolidColorBrush.Parse("#727272"), Foreground = SolidColorBrush.Parse("#727272"),
Margin = new Thickness(0, 0, 0, 10) 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 { Width = 200, Watermark="Floating Watermark", UseFloatingWatermark = true },
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 new TextBlock
{ {
Margin = new Thickness(0, 40, 0, 0), Margin = new Thickness(0, 40, 0, 0),

18
src/Perspex.Controls/TextBox.cs

@ -39,6 +39,12 @@ namespace Perspex.Controls
public static readonly PerspexProperty<TextWrapping> TextWrappingProperty = public static readonly PerspexProperty<TextWrapping> TextWrappingProperty =
TextBlock.TextWrappingProperty.AddOwner<TextBox>(); TextBlock.TextWrappingProperty.AddOwner<TextBox>();
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; private TextPresenter _presenter;
static TextBox() static TextBox()
@ -101,6 +107,18 @@ namespace Perspex.Controls
set { SetValue(TextProperty, value); } set { SetValue(TextProperty, value); }
} }
public string Watermark
{
get { return GetValue(WatermarkProperty); }
set { SetValue(WatermarkProperty, value); }
}
public bool UseFloatingWatermark
{
get { return GetValue(UseFloatingWatermarkProperty); }
set { SetValue(UseFloatingWatermarkProperty, value); }
}
public TextWrapping TextWrapping public TextWrapping TextWrapping
{ {
get { return GetValue(TextWrappingProperty); } get { return GetValue(TextWrappingProperty); }

53
src/Perspex.Themes.Default/TextBoxStyle.cs

@ -8,6 +8,7 @@ using Perspex.Controls.Primitives;
using Perspex.Controls.Templates; using Perspex.Controls.Templates;
using Perspex.Media; using Perspex.Media;
using Perspex.Styling; using Perspex.Styling;
using System.Reactive.Linq;
namespace Perspex.Themes.Default namespace Perspex.Themes.Default
{ {
@ -58,21 +59,49 @@ namespace Perspex.Themes.Default
[~Border.BackgroundProperty] = control[~TemplatedControl.BackgroundProperty], [~Border.BackgroundProperty] = control[~TemplatedControl.BackgroundProperty],
[~Border.BorderBrushProperty] = control[~TemplatedControl.BorderBrushProperty], [~Border.BorderBrushProperty] = control[~TemplatedControl.BorderBrushProperty],
[~Border.BorderThicknessProperty] = control[~TemplatedControl.BorderThicknessProperty], [~Border.BorderThicknessProperty] = control[~TemplatedControl.BorderThicknessProperty],
Child = new ScrollViewer
Child = new StackPanel
{ {
[~ScrollViewer.CanScrollHorizontallyProperty] = control[~ScrollViewer.CanScrollHorizontallyProperty], Children = new Controls.Controls
[~ScrollViewer.HorizontalScrollBarVisibilityProperty] = control[~ScrollViewer.HorizontalScrollBarVisibilityProperty],
[~ScrollViewer.VerticalScrollBarVisibilityProperty] = control[~ScrollViewer.VerticalScrollBarVisibilityProperty],
Content = new TextPresenter
{ {
Name = "textPresenter", new TextBlock
[~TextPresenter.CaretIndexProperty] = control[~TextBox.CaretIndexProperty], {
[~TextPresenter.SelectionStartProperty] = control[~TextBox.SelectionStartProperty], Name = "floatingWatermark",
[~TextPresenter.SelectionEndProperty] = control[~TextBox.SelectionEndProperty], Foreground = SolidColorBrush.Parse("#007ACC"),
[~TextBlock.TextProperty] = control[~TextBox.TextProperty], FontSize = 10,
[~TextBlock.TextWrappingProperty] = control[~TextBox.TextWrappingProperty], [~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; return result;

Loading…
Cancel
Save