Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RFC] [WIP] Watermark Enhancements #2898

Closed
wants to merge 11 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public class SpellCheckSeparator : Separator, ISpellCheckMenuItem
{
}

public enum FloatingWatermark { Interior, Exterior };

/// <summary>
/// A helper class that provides various attached properties for the TextBox control.
/// </summary>
Expand All @@ -42,6 +44,9 @@ public class TextBoxHelper
public static readonly DependencyProperty IsMonitoringProperty = DependencyProperty.RegisterAttached("IsMonitoring", typeof(bool), typeof(TextBoxHelper), new UIPropertyMetadata(false, OnIsMonitoringChanged));
public static readonly DependencyProperty WatermarkProperty = DependencyProperty.RegisterAttached("Watermark", typeof(string), typeof(TextBoxHelper), new UIPropertyMetadata(string.Empty));
public static readonly DependencyProperty UseFloatingWatermarkProperty = DependencyProperty.RegisterAttached("UseFloatingWatermark", typeof(bool), typeof(TextBoxHelper), new FrameworkPropertyMetadata(false, ButtonCommandOrClearTextChanged));
public static readonly DependencyProperty FloatingWatermarkLocationProperty = DependencyProperty.RegisterAttached("FloatingWatermarkLocation", typeof(FloatingWatermark), typeof(TextBoxHelper), new FrameworkPropertyMetadata(FloatingWatermark.Interior, ButtonCommandOrClearTextChanged));
public static readonly DependencyProperty FloatingWatermarkOverrideTextProperty = DependencyProperty.RegisterAttached("FloatingWatermarkOverrideText", typeof(string), typeof(TextBoxHelper), new UIPropertyMetadata(string.Empty));
public static readonly DependencyProperty WatermarkTrimmingProperty = DependencyProperty.RegisterAttached("WatermarkTrimming", typeof(TextTrimming), typeof(TextBoxHelper), new FrameworkPropertyMetadata(TextTrimming.CharacterEllipsis));
public static readonly DependencyProperty TextLengthProperty = DependencyProperty.RegisterAttached("TextLength", typeof(int), typeof(TextBoxHelper), new UIPropertyMetadata(0));
public static readonly DependencyProperty ClearTextButtonProperty = DependencyProperty.RegisterAttached("ClearTextButton", typeof(bool), typeof(TextBoxHelper), new FrameworkPropertyMetadata(false, ButtonCommandOrClearTextChanged));
public static readonly DependencyProperty TextButtonProperty = DependencyProperty.RegisterAttached("TextButton", typeof(bool), typeof(TextBoxHelper), new FrameworkPropertyMetadata(false, ButtonCommandOrClearTextChanged));
Expand Down Expand Up @@ -415,6 +420,8 @@ public static void SetWatermark(DependencyObject obj, string value)
[AttachedPropertyBrowsableForType(typeof(PasswordBox))]
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
[AttachedPropertyBrowsableForType(typeof(NumericUpDown))]
[AttachedPropertyBrowsableForType(typeof(DatePicker))]
[AttachedPropertyBrowsableForType(typeof(TimePickerBase))]
public static bool GetUseFloatingWatermark(DependencyObject obj)
{
return (bool)obj.GetValue(UseFloatingWatermarkProperty);
Expand All @@ -424,7 +431,58 @@ public static void SetUseFloatingWatermark(DependencyObject obj, bool value)
{
obj.SetValue(UseFloatingWatermarkProperty, value);
}


[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(TextBoxBase))]
[AttachedPropertyBrowsableForType(typeof(PasswordBox))]
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
[AttachedPropertyBrowsableForType(typeof(NumericUpDown))]
[AttachedPropertyBrowsableForType(typeof(DatePicker))]
[AttachedPropertyBrowsableForType(typeof(TimePickerBase))]
public static FloatingWatermark GetFloatingWatermarkLocation(DependencyObject obj)
{
return (FloatingWatermark)obj.GetValue(FloatingWatermarkLocationProperty);
}

public static void SetFloatingWatermarkLocation(DependencyObject obj, FloatingWatermark value)
{
obj.SetValue(FloatingWatermarkLocationProperty, value);
}

[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(TextBoxBase))]
[AttachedPropertyBrowsableForType(typeof(PasswordBox))]
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
[AttachedPropertyBrowsableForType(typeof(DatePicker))]
[AttachedPropertyBrowsableForType(typeof(TimePickerBase))]
[AttachedPropertyBrowsableForType(typeof(NumericUpDown))]
public static string GetFloatingWatermarkOverrideText(DependencyObject obj)
{
return (string)obj.GetValue(FloatingWatermarkOverrideTextProperty);
}

public static void SetFloatingWatermarkOverrideText(DependencyObject obj, string value)
{
obj.SetValue(FloatingWatermarkOverrideTextProperty, value);
}

[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(TextBoxBase))]
[AttachedPropertyBrowsableForType(typeof(PasswordBox))]
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
[AttachedPropertyBrowsableForType(typeof(DatePicker))]
[AttachedPropertyBrowsableForType(typeof(TimePickerBase))]
[AttachedPropertyBrowsableForType(typeof(NumericUpDown))]
public static TextTrimming GetWatermarkTrimming(DependencyObject obj)
{
return (TextTrimming)obj.GetValue(WatermarkTrimmingProperty);
}

public static void SetWatermarkTrimming(DependencyObject obj, TextTrimming value)
{
obj.SetValue(WatermarkTrimmingProperty, value);
}

/// <summary>
/// Gets if the attached TextBox has text.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
using System;
using System.Globalization;
using System.Windows;
using System.Windows.Data;

namespace MahApps.Metro.Converters
{
public class FloatingWatermarkOverrideTextLengthToBooleanConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
if (value.ToString().Length > 0)
{ return true; }
else
{ return false; }
}

public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
return Binding.DoNothing;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@
<Compile Include="$(MSBuildThisFileDirectory)Controls\WindowSettings.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\BackgroundToForegroundConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\ClockDegreeConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\FloatingWatermarkOverrideTextLengthToBooleanConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\FontSizeOffsetConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\IsNullConverter.cs" />
<Compile Include="$(MSBuildThisFileDirectory)Converters\MarkupConverter.cs" />
Expand Down
Loading