Skip to content

Commit

Permalink
Merge pull request #2387 from MahApps/MetroButton-style-TextBoxHelper…
Browse files Browse the repository at this point in the history
…-TextButton

MetroButtonPasswordBox / MetroButtonTextBox fixes for #2385 and #2220
  • Loading branch information
punker76 committed Mar 1, 2016
2 parents da1bb52 + dca679c commit 3ca4c98
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 3 deletions.
24 changes: 24 additions & 0 deletions MahApps.Metro/Controls/Helper/TextBoxHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ public class TextBoxHelper
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));
public static readonly DependencyProperty TextButtonProperty = DependencyProperty.RegisterAttached("TextButton", typeof(bool), typeof(TextBoxHelper), new FrameworkPropertyMetadata(false, ButtonCommandOrClearTextChanged));
public static readonly DependencyProperty ButtonsAlignmentProperty = DependencyProperty.RegisterAttached("ButtonsAlignment", typeof(ButtonsAlignment), typeof(TextBoxHelper), new FrameworkPropertyMetadata(ButtonsAlignment.Right, FrameworkPropertyMetadataOptions.AffectsArrange | FrameworkPropertyMetadataOptions.AffectsMeasure));
/// <summary>
/// The clear text button behavior property. It sets a click event to the button if the value is true.
Expand Down Expand Up @@ -329,17 +330,40 @@ private static void ControlGotFocus<TDependencyObject>(TDependencyObject sender,
}
}

/// <summary>
/// Gets the clear text button visibility / feature. Can be used to enable text deletion.
/// </summary>
[Category(AppName.MahApps)]
public static bool GetClearTextButton(DependencyObject d)
{
return (bool)d.GetValue(ClearTextButtonProperty);
}

/// <summary>
/// Sets the clear text button visibility / feature. Can be used to enable text deletion.
/// </summary>
public static void SetClearTextButton(DependencyObject obj, bool value)
{
obj.SetValue(ClearTextButtonProperty, value);
}

/// <summary>
/// Gets the text button visibility.
/// </summary>
[Category(AppName.MahApps)]
public static bool GetTextButton(DependencyObject d)
{
return (bool)d.GetValue(TextButtonProperty);
}

/// <summary>
/// Sets the text button visibility.
/// </summary>
public static void SetTextButton(DependencyObject obj, bool value)
{
obj.SetValue(TextButtonProperty, value);
}

/// <summary>
/// Gets the buttons placement variant.
/// </summary>
Expand Down
4 changes: 3 additions & 1 deletion MahApps.Metro/Styles/Controls.PasswordBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,7 @@
<Style x:Key="MetroButtonPasswordBox"
BasedOn="{StaticResource MetroPasswordBox}"
TargetType="{x:Type PasswordBox}">
<Setter Property="Controls:TextBoxHelper.TextButton" Value="True" />
<Setter Property="Controls:TextBoxHelper.ButtonTemplate" Value="{DynamicResource ChromelessButtonTemplate}" />
<Setter Property="Template">
<Setter.Value>
Expand Down Expand Up @@ -439,7 +440,8 @@
Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ButtonContent), Mode=OneWay}"
ContentTemplate="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ButtonContentTemplate), Mode=OneWay}"
IsTabStop="False"
Template="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ButtonTemplate), Mode=OneWay}" />
Template="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ButtonTemplate), Mode=OneWay}"
Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.TextButton), Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}" />
</Grid>
<Border x:Name="DisabledVisualElement"
Background="{DynamicResource ControlsDisabledBrush}"
Expand Down
6 changes: 4 additions & 2 deletions MahApps.Metro/Styles/Controls.TextBox.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@
<Style x:Key="MetroButtonTextBox"
BasedOn="{StaticResource MetroTextBox}"
TargetType="{x:Type TextBox}">
<Setter Property="Controls:TextBoxHelper.TextButton" Value="True" />
<Setter Property="Controls:TextBoxHelper.ButtonTemplate" Value="{DynamicResource ChromelessButtonTemplate}" />
<!-- change SnapsToDevicePixels to True to view a better border and validation error -->
<Setter Property="Template">
Expand Down Expand Up @@ -353,7 +354,8 @@
Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ButtonContent), Mode=OneWay}"
ContentTemplate="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ButtonContentTemplate), Mode=OneWay}"
IsTabStop="False"
Template="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ButtonTemplate), Mode=OneWay}" />
Template="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ButtonTemplate), Mode=OneWay}"
Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.TextButton), Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}" />
</Grid>
<Border x:Name="DisabledVisualElement"
Background="{DynamicResource ControlsDisabledBrush}"
Expand Down Expand Up @@ -393,7 +395,7 @@
<MultiDataTrigger>
<MultiDataTrigger.Conditions>
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:TextBoxHelper.ButtonsAlignment)}" Value="Right" />
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:TextBoxHelper.ClearTextButton)}" Value="False" />
<Condition Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:TextBoxHelper.TextButton)}" Value="False" />
</MultiDataTrigger.Conditions>
<Setter TargetName="PART_ContentHost" Property="Grid.ColumnSpan" Value="2" />
<Setter TargetName="PART_Message" Property="Grid.ColumnSpan" Value="2" />
Expand Down

0 comments on commit 3ca4c98

Please sign in to comment.