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

Watermark fixes and improvements #3069

Merged
merged 5 commits into from
Oct 6, 2017
Merged
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
10 changes: 10 additions & 0 deletions docs/release-notes/1.6.0.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
- `Badged` control has now a different look when disabled. thx [@xxMUROxx](https://github.com/xxMUROxx)
+ Adds new brush to light and dark themes `MahApps.Metro.Brushes.Badged.DisabledBackgroundBrush`
- Don't catch `TextChangedEvent` in `NumericUpDown` [#3066](https://github.com/MahApps/MahApps.Metro/pull/3066) [@Silv3rcircl3](https://github.com/Silv3rcircl3)
- `Watermark` fixes and improvements
+ Fix right aligned floating watermark.
+ Use `TextBoxHelper.Watermark` for `HotKeyBox` instead own DependencyProperty (marked as obsolete).
+ Allow `TextBoxHelper.AutoWatermark` for `HotKey` DependencyProperty of `HotKeyBox`.
+ New `TextBoxHelper.WatermarkTrimming` attached property to set the text trimming behavior to employ when (floating) watermark overflows the content area. thx to [@amkuchta](https://github.com/amkuchta)
+ New `TextBoxHelper.WatermarkWrapping` attached property (only for `TextBox`) to set how the watermark should wrap text. Default is binded to `TextWrapping` property. thx to [@amkuchta](https://github.com/amkuchta)

## Breaking Change

Expand Down Expand Up @@ -87,3 +93,7 @@ More informations about the reason of this decision can be found here:
- [#3017](https://github.com/MahApps/MahApps.Metro/issues/3017) SplitButton with custom ItemTemplate - Source change does not always update layout
- [#2977](https://github.com/MahApps/MahApps.Metro/issues/2977) Badge must have a different look when disabled
- [#2937](https://github.com/MahApps/MahApps.Metro/issues/2937) Fuzzy button outline [#3064](https://github.com/MahApps/MahApps.Metro/pull/3064) [@n00bje](https://github.com/n00bje)
- [#3067](https://github.com/MahApps/MahApps.Metro/issues/3067) Right aligned floating Watermark goes behind clear button
- [#3068](https://github.com/MahApps/MahApps.Metro/issues/3068) AutoWatermark attached property has no effect on HotKeyBox
- [#2884](https://github.com/MahApps/MahApps.Metro/issues/2884) [Feature Request] Watermark Trimming
- [#2889](https://github.com/MahApps/MahApps.Metro/issues/2889) [Feature Request] Watermark Wrapping
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ 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 WatermarkAlignmentProperty = DependencyProperty.RegisterAttached("WatermarkAlignment", typeof(TextAlignment), typeof(TextBoxHelper), new FrameworkPropertyMetadata(TextAlignment.Left, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender | FrameworkPropertyMetadataOptions.Inherits));
public static readonly DependencyProperty WatermarkTrimmingProperty = DependencyProperty.RegisterAttached("WatermarkTrimming", typeof(TextTrimming), typeof(TextBoxHelper), new FrameworkPropertyMetadata(TextTrimming.None, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender));
public static readonly DependencyProperty WatermarkWrappingProperty = DependencyProperty.RegisterAttached("WatermarkWrapping", typeof(TextWrapping), typeof(TextBoxHelper), new FrameworkPropertyMetadata(TextWrapping.NoWrap, FrameworkPropertyMetadataOptions.AffectsMeasure | FrameworkPropertyMetadataOptions.AffectsRender));
public static readonly DependencyProperty UseFloatingWatermarkProperty = DependencyProperty.RegisterAttached("UseFloatingWatermark", typeof(bool), typeof(TextBoxHelper), new FrameworkPropertyMetadata(false, ButtonCommandOrClearTextChanged));
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));
Expand Down Expand Up @@ -85,6 +87,7 @@ public class TextBoxHelper
{ typeof(TextBox), TextBox.TextProperty },
{ typeof(ComboBox), Selector.SelectedItemProperty },
{ typeof(NumericUpDown), NumericUpDown.ValueProperty },
{ typeof(HotKeyBox), HotKeyBox.HotKeyProperty },
{ typeof(DatePicker), DatePicker.SelectedDateProperty },
{ typeof(TimePicker), TimePickerBase.SelectedTimeProperty },
{ typeof(DateTimePicker), DateTimePicker.SelectedDateProperty }
Expand Down Expand Up @@ -112,6 +115,7 @@ public static void SetIsSpellCheckContextMenuEnabled(UIElement element, bool val
[AttachedPropertyBrowsableForType(typeof(DatePicker))]
[AttachedPropertyBrowsableForType(typeof(TimePickerBase))]
[AttachedPropertyBrowsableForType(typeof(NumericUpDown))]
[AttachedPropertyBrowsableForType(typeof(HotKeyBox))]
public static bool GetAutoWatermark(DependencyObject element)
{
return (bool)element.GetValue(AutoWatermarkProperty);
Expand Down Expand Up @@ -428,6 +432,7 @@ public static void SetIsMonitoring(DependencyObject obj, bool value)
[AttachedPropertyBrowsableForType(typeof(DatePicker))]
[AttachedPropertyBrowsableForType(typeof(TimePickerBase))]
[AttachedPropertyBrowsableForType(typeof(NumericUpDown))]
[AttachedPropertyBrowsableForType(typeof(HotKeyBox))]
public static string GetWatermark(DependencyObject obj)
{
return (string)obj.GetValue(WatermarkProperty);
Expand All @@ -451,6 +456,7 @@ public static void SetWatermark(DependencyObject obj, string value)
[AttachedPropertyBrowsableForType(typeof(DatePicker))]
[AttachedPropertyBrowsableForType(typeof(TimePickerBase))]
[AttachedPropertyBrowsableForType(typeof(NumericUpDown))]
[AttachedPropertyBrowsableForType(typeof(HotKeyBox))]
public static TextAlignment GetWatermarkAlignment(DependencyObject obj)
{
return (TextAlignment)obj.GetValue(WatermarkAlignmentProperty);
Expand All @@ -466,16 +472,75 @@ public static TextAlignment GetWatermarkAlignment(DependencyObject obj)
[AttachedPropertyBrowsableForType(typeof(DatePicker))]
[AttachedPropertyBrowsableForType(typeof(TimePickerBase))]
[AttachedPropertyBrowsableForType(typeof(NumericUpDown))]
[AttachedPropertyBrowsableForType(typeof(HotKeyBox))]
public static void SetWatermarkAlignment(DependencyObject obj, TextAlignment value)
{
obj.SetValue(WatermarkAlignmentProperty, value);
}

/// <summary>
/// Gets the text trimming behavior to employ when watermark overflows the content area.
/// </summary>
/// <returns>
/// One of the <see cref="T:System.Windows.TextTrimming" /> values that specifies the text trimming behavior to employ. The default is <see cref="F:System.Windows.TextTrimming.None" />.
/// </returns>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(TextBoxBase))]
[AttachedPropertyBrowsableForType(typeof(PasswordBox))]
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
[AttachedPropertyBrowsableForType(typeof(DatePicker))]
[AttachedPropertyBrowsableForType(typeof(TimePickerBase))]
[AttachedPropertyBrowsableForType(typeof(NumericUpDown))]
[AttachedPropertyBrowsableForType(typeof(HotKeyBox))]
public static TextTrimming GetWatermarkTrimming(DependencyObject obj)
{
return (TextTrimming)obj.GetValue(WatermarkTrimmingProperty);
}

/// <summary>
/// Sets the text trimming behavior to employ when watermark overflows the content area.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(TextBoxBase))]
[AttachedPropertyBrowsableForType(typeof(PasswordBox))]
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
[AttachedPropertyBrowsableForType(typeof(DatePicker))]
[AttachedPropertyBrowsableForType(typeof(TimePickerBase))]
[AttachedPropertyBrowsableForType(typeof(NumericUpDown))]
[AttachedPropertyBrowsableForType(typeof(HotKeyBox))]
public static void SetWatermarkTrimming(DependencyObject obj, TextTrimming value)
{
obj.SetValue(WatermarkTrimmingProperty, value);
}

/// <summary>
/// Gets how the watermark should wrap text.
/// </summary>
/// <returns>One of the <see cref="T:System.Windows.TextWrapping" /> values. The default is <see cref="F:System.Windows.TextWrapping.NoWrap" />.
/// </returns>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(TextBoxBase))]
public static TextWrapping GetWatermarkWrapping(DependencyObject obj)
{
return (TextWrapping)obj.GetValue(WatermarkWrappingProperty);
}

/// <summary>
/// Sets how the watermark should wrap text.
/// </summary>
[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(TextBoxBase))]
public static void SetWatermarkWrapping(DependencyObject obj, TextWrapping value)
{
obj.SetValue(WatermarkWrappingProperty, value);
}

[Category(AppName.MahApps)]
[AttachedPropertyBrowsableForType(typeof(TextBoxBase))]
[AttachedPropertyBrowsableForType(typeof(PasswordBox))]
[AttachedPropertyBrowsableForType(typeof(ComboBox))]
[AttachedPropertyBrowsableForType(typeof(NumericUpDown))]
[AttachedPropertyBrowsableForType(typeof(HotKeyBox))]
public static bool GetUseFloatingWatermark(DependencyObject obj)
{
return (bool)obj.GetValue(UseFloatingWatermarkProperty);
Expand Down
2 changes: 2 additions & 0 deletions src/MahApps.Metro/MahApps.Metro.Shared/Controls/HotKeyBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,11 @@ public bool AreModifierKeysRequired
set { SetValue(AreModifierKeysRequiredProperty, value); }
}

[Obsolete("This property will be deleted in the next release. Instead use TextBoxHelper.Watermark attached property.")]
public static readonly DependencyProperty WatermarkProperty = DependencyProperty.Register(
"Watermark", typeof(string), typeof(HotKeyBox), new PropertyMetadata(default(string)));

[Obsolete("This property will be deleted in the next release. Instead use TextBoxHelper.Watermark attached property.")]
public string Watermark
{
get { return (string) GetValue(WatermarkProperty); }
Expand Down
10 changes: 7 additions & 3 deletions src/MahApps.Metro/MahApps.Metro/Styles/Controls.ComboBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -76,19 +76,20 @@
Style="{DynamicResource MahApps.Metro.Styles.MetroWatermarkTextBlock}"
Text="{TemplateBinding Controls:TextBoxHelper.Watermark}"
TextAlignment="{TemplateBinding Controls:TextBoxHelper.WatermarkAlignment}"
TextTrimming="{TemplateBinding Controls:TextBoxHelper.WatermarkTrimming}"
Visibility="Collapsed" />
<ContentControl x:Name="PART_FloatingMessageContainer"
Grid.Row="0"
Grid.Column="0"
Grid.ColumnSpan="2"
Style="{DynamicResource FloatingMessageContainerStyle}">
<TextBlock x:Name="PART_FloatingMessage"
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Foreground="{TemplateBinding Foreground}"
Style="{DynamicResource MetroAutoCollapsingTextBlock}"
Text="{TemplateBinding Controls:TextBoxHelper.Watermark}"
TextAlignment="{TemplateBinding Controls:TextBoxHelper.WatermarkAlignment}" />
TextAlignment="{TemplateBinding Controls:TextBoxHelper.WatermarkAlignment}"
TextTrimming="{TemplateBinding Controls:TextBoxHelper.WatermarkTrimming}" />
</ContentControl>
<Button x:Name="PART_ClearText"
Grid.Row="0"
Expand Down Expand Up @@ -347,6 +348,7 @@
Controls:TextBoxHelper.UseFloatingWatermark="{TemplateBinding Controls:TextBoxHelper.UseFloatingWatermark}"
Controls:TextBoxHelper.Watermark="{TemplateBinding Controls:TextBoxHelper.Watermark}"
Controls:TextBoxHelper.WatermarkAlignment="{TemplateBinding Controls:TextBoxHelper.WatermarkAlignment}"
Controls:TextBoxHelper.WatermarkTrimming="{TemplateBinding Controls:TextBoxHelper.WatermarkTrimming}"
Background="{x:Null}"
BorderThickness="0"
CharacterCasing="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ComboBoxHelper.CharacterCasing), Mode=OneWay}"
Expand All @@ -371,6 +373,7 @@
Style="{DynamicResource MahApps.Metro.Styles.MetroWatermarkTextBlock}"
Text="{TemplateBinding Controls:TextBoxHelper.Watermark}"
TextAlignment="{TemplateBinding Controls:TextBoxHelper.WatermarkAlignment}"
TextTrimming="{TemplateBinding Controls:TextBoxHelper.WatermarkTrimming}"
Visibility="Collapsed" />
<ContentControl x:Name="PART_FloatingMessageContainer"
Grid.Row="0"
Expand All @@ -383,7 +386,8 @@
Foreground="{TemplateBinding Foreground}"
Style="{DynamicResource MetroAutoCollapsingTextBlock}"
Text="{TemplateBinding Controls:TextBoxHelper.Watermark}"
TextAlignment="{TemplateBinding Controls:TextBoxHelper.WatermarkAlignment}" />
TextAlignment="{TemplateBinding Controls:TextBoxHelper.WatermarkAlignment}"
TextTrimming="{TemplateBinding Controls:TextBoxHelper.WatermarkTrimming}" />
</ContentControl>

<Grid x:Name="ContentSite"
Expand Down
Loading