Permalink
Browse files

Removed some hardcoded/unsuitable fonts and styles, reverted names (a…

…lthough not functionality) to textboxhelper.
  • Loading branch information...
vikingcode committed Apr 24, 2012
1 parent d3c5f66 commit f6e14d094292c889d1fea5d153af34fa21a1a4b0
@@ -5,10 +5,80 @@
namespace MahApps.Metro.Controls
{
- public static class TextboxHelper
+ /// <summary>
+ /// Password watermarking code from: http://prabu-guru.blogspot.com/2010/06/how-to-add-watermark-text-to-textbox.html
+ /// </summary>
+ public class TextboxHelper : DependencyObject
{
+ 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));
+ private static readonly DependencyProperty HasTextProperty = DependencyProperty.RegisterAttached("HasText", typeof(bool), typeof(TextboxHelper), new FrameworkPropertyMetadata(false));
+ 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, ClearTextChanged));
+ public static void SetIsMonitoring(DependencyObject obj, bool value)
+ {
+ obj.SetValue(IsMonitoringProperty, value);
+ }
+
+ public static string GetWatermark(DependencyObject obj)
+ {
+ return (string)obj.GetValue(WatermarkProperty);
+ }
+
+ public static void SetWatermark(DependencyObject obj, string value)
+ {
+ obj.SetValue(WatermarkProperty, value);
+ }
+
+
+ private static void SetTextLength(DependencyObject obj, int value)
+ {
+ obj.SetValue(TextLengthProperty, value);
+ obj.SetValue(HasTextProperty, value >= 1);
+ }
+
+ public bool HasText
+ {
+ get { return (bool)GetValue(HasTextProperty); }
+ }
+
+ static void OnIsMonitoringChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
+ {
+ if (d is TextBox)
+ {
+ var txtBox = d as TextBox;
+
+ if ((bool)e.NewValue)
+ txtBox.TextChanged += TextChanged;
+ else
+ txtBox.TextChanged -= TextChanged;
+ }
+ else if (d is PasswordBox)
+ {
+ var passBox = d as PasswordBox;
+
+ if ((bool)e.NewValue)
+ passBox.PasswordChanged += PasswordChanged;
+ else
+ passBox.PasswordChanged -= PasswordChanged;
+ }
+ }
+
+ static void TextChanged(object sender, TextChangedEventArgs e)
+ {
+ var txtBox = sender as TextBox;
+ if (txtBox == null) return;
+ SetTextLength(txtBox, txtBox.Text.Length);
+ }
+
+ static void PasswordChanged(object sender, RoutedEventArgs e)
+ {
+ var passBox = sender as PasswordBox;
+ if (passBox == null) return;
+ SetTextLength(passBox, passBox.Password.Length);
+ }
+
public static bool GetClearTextButton(DependencyObject d)
{
return (bool)d.GetValue(ClearTextButtonProperty);
@@ -64,4 +134,5 @@ static void ClearTextClicked(object sender, RoutedEventArgs e)
((TextBox)parent).Text = string.Empty;
}
}
+
}
@@ -1,85 +0,0 @@
-using System.Windows;
-using System.Windows.Controls;
-
-namespace MahApps.Metro.Controls
-{
- /// <summary>
- /// Original code: http://prabu-guru.blogspot.com/2010/06/how-to-add-watermark-text-to-textbox.html
- /// </summary>
- public class WaterMarkTextHelper : DependencyObject
- {
- public static void SetIsMonitoring(DependencyObject obj, bool value)
- {
- obj.SetValue(IsMonitoringProperty, value);
- }
-
- public static readonly DependencyProperty IsMonitoringProperty =
- DependencyProperty.RegisterAttached("IsMonitoring", typeof(bool), typeof(WaterMarkTextHelper), new UIPropertyMetadata(false, OnIsMonitoringChanged));
-
- public static string GetWatermarkText(DependencyObject obj)
- {
- return (string)obj.GetValue(WatermarkTextProperty);
- }
-
- public static void SetWatermarkText(DependencyObject obj, string value)
- {
- obj.SetValue(WatermarkTextProperty, value);
- }
-
- public static readonly DependencyProperty WatermarkTextProperty =
- DependencyProperty.RegisterAttached("WatermarkText", typeof(string), typeof(WaterMarkTextHelper), new UIPropertyMetadata(string.Empty));
-
- private static void SetTextLength(DependencyObject obj, int value)
- {
- obj.SetValue(TextLengthProperty, value);
- obj.SetValue(HasTextProperty, value >= 1);
- }
-
- public static readonly DependencyProperty TextLengthProperty =
- DependencyProperty.RegisterAttached("TextLength", typeof(int), typeof(WaterMarkTextHelper), new UIPropertyMetadata(0));
-
- public bool HasText
- {
- get { return (bool)GetValue(HasTextProperty); }
- }
-
- private static readonly DependencyProperty HasTextProperty =
- DependencyProperty.RegisterAttached("HasText", typeof(bool), typeof(WaterMarkTextHelper), new FrameworkPropertyMetadata(false));
-
- static void OnIsMonitoringChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
- {
- if (d is TextBox)
- {
- var txtBox = d as TextBox;
-
- if ((bool)e.NewValue)
- txtBox.TextChanged += TextChanged;
- else
- txtBox.TextChanged -= TextChanged;
- }
- else if (d is PasswordBox)
- {
- var passBox = d as PasswordBox;
-
- if ((bool)e.NewValue)
- passBox.PasswordChanged += PasswordChanged;
- else
- passBox.PasswordChanged -= PasswordChanged;
- }
- }
-
- static void TextChanged(object sender, TextChangedEventArgs e)
- {
- var txtBox = sender as TextBox;
- if (txtBox == null) return;
- SetTextLength(txtBox, txtBox.Text.Length);
- }
-
- static void PasswordChanged(object sender, RoutedEventArgs e)
- {
- var passBox = sender as PasswordBox;
- if (passBox == null) return;
- SetTextLength(passBox, passBox.Password.Length);
- }
- }
-}
@@ -60,7 +60,6 @@
<Compile Include="Controls\ClosingWindowEventHandlerArgs.cs" />
<Compile Include="Controls\Planerator.cs" />
<Compile Include="Controls\TextboxHelper.cs" />
- <Compile Include="Controls\WaterMarkTextHelper.cs" />
<Compile Include="Controls\WindowCommands.cs" />
<Compile Include="Native\WINDOWPLACEMENT.cs" />
<Compile Include="Controls\WindowSettings.cs" />
@@ -292,7 +292,7 @@
<!--PasswordBox Style-->
<Style TargetType="{x:Type PasswordBox}">
- <Setter Property="Controls:WaterMarkTextHelper.IsMonitoring" Value="True"/>
+ <Setter Property="Controls:TextboxHelper.IsMonitoring" Value="True"/>
<Setter Property="SelectionBrush" Value="{DynamicResource HighlightBrush}" />
<Setter Property="FontFamily" Value="{DynamicResource ContentFontFamily}" />
<Setter Property="FontSize" Value="{DynamicResource ContentFontSize}" />
@@ -360,9 +360,9 @@
<Grid Margin="2">
<Border x:Name="ReadOnlyVisualElement" Background="{x:Null}" Opacity="0" />
<ScrollViewer x:Name="PART_ContentHost" BorderThickness="0" IsTabStop="False" Margin="2" VerticalAlignment="Stretch" Background="{x:Null}" />
- <TextBlock x:Name="Message" FontStyle="Italic"
- Text="{TemplateBinding Controls:WaterMarkTextHelper.WatermarkText}"
- Foreground="{DynamicResource TextBrush}" IsHitTestVisible="False" FontFamily="Calibri"
+ <TextBlock x:Name="Message"
+ Text="{TemplateBinding Controls:TextboxHelper.Watermark}"
+ Foreground="{DynamicResource TextBrush}" IsHitTestVisible="False"
Opacity="0.6" HorizontalAlignment="Left" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" Margin="6,0,0,0"/>
</Grid>
<Rectangle x:Name="DisabledVisualElement"
@@ -414,7 +414,7 @@
<MultiTrigger>
<MultiTrigger.Conditions>
- <Condition Property="Controls:WaterMarkTextHelper.HasText" Value="False"/>
+ <Condition Property="Controls:TextboxHelper.HasText" Value="False"/>
<Condition Property="IsFocused" Value="True"/>
</MultiTrigger.Conditions>
<MultiTrigger.EnterActions>
@@ -425,7 +425,7 @@
</MultiTrigger.ExitActions>
</MultiTrigger>
- <Trigger Property="Controls:WaterMarkTextHelper.HasText" Value="True">
+ <Trigger Property="Controls:TextboxHelper.HasText" Value="True">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource enterHasText}"/>
</Trigger.EnterActions>
@@ -782,7 +782,7 @@
<!--TextBox Style-->
<Style TargetType="{x:Type TextBox}">
- <Setter Property="Controls:WaterMarkTextHelper.IsMonitoring" Value="True"/>
+ <Setter Property="Controls:TextboxHelper.IsMonitoring" Value="True"/>
<Setter Property="SelectionBrush" Value="{DynamicResource HighlightBrush}" />
<Setter Property="FontFamily" Value="{DynamicResource ContentFontFamily}" />
<Setter Property="FontSize" Value="{DynamicResource ContentFontSize}" />
@@ -850,8 +850,8 @@
<Grid Margin="2">
<Border x:Name="ReadOnlyVisualElement" Background="{x:Null}" Opacity="0" />
<ScrollViewer x:Name="PART_ContentHost" BorderThickness="0" IsTabStop="False" Margin="2" VerticalAlignment="Stretch" Background="{x:Null}" />
- <TextBlock x:Name="Message" Text="{TemplateBinding Controls:WaterMarkTextHelper.WatermarkText}" FontStyle="Italic"
- Foreground="{DynamicResource TextBrush}" IsHitTestVisible="False" FontFamily="Calibri" Opacity="0.6" HorizontalAlignment="Left" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
+ <TextBlock x:Name="Message" Text="{TemplateBinding Controls:TextboxHelper.Watermark}"
+ Foreground="{DynamicResource TextBrush}" IsHitTestVisible="False" Opacity="0.6" HorizontalAlignment="Left" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
Margin="6,0,0,0"/>
<Button x:Name="PART_ClearText" Style="{DynamicResource ChromelessButtonStyle}" Width="20" HorizontalAlignment="Right" FontFamily="Marlett" Content="r" Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextboxHelper.ClearTextButton), Converter={StaticResource BooleanToVisibilityConverter}}" />
@@ -918,7 +918,7 @@
<MultiTrigger>
<MultiTrigger.Conditions>
- <Condition Property="Controls:WaterMarkTextHelper.HasText" Value="False"/>
+ <Condition Property="Controls:TextboxHelper.HasText" Value="False"/>
<Condition Property="IsFocused" Value="True"/>
</MultiTrigger.Conditions>
<MultiTrigger.EnterActions>
@@ -929,7 +929,7 @@
</MultiTrigger.ExitActions>
</MultiTrigger>
- <Trigger Property="Controls:WaterMarkTextHelper.HasText" Value="True">
+ <Trigger Property="Controls:TextboxHelper.HasText" Value="True">
<Trigger.EnterActions>
<BeginStoryboard Storyboard="{StaticResource enterHasText}"/>
</Trigger.EnterActions>
@@ -62,7 +62,7 @@
</ContextMenu>
</Button.ContextMenu>
</Button>
- <PasswordBox Controls:WaterMarkTextHelper.WatermarkText="Enter Password"
+ <PasswordBox Controls:TextboxHelper.Watermark="Enter Password"
Margin="88.695,66.96,0,0"
VerticalAlignment="Top"
HorizontalAlignment="Left"
@@ -77,7 +77,7 @@
VerticalAlignment="Top"
GroupName="test"
HorizontalAlignment="Left" />
- <TextBox Controls:WaterMarkTextHelper.WatermarkText="Enter Username"
+ <TextBox Controls:TextboxHelper.Watermark="Enter Username"
Controls:TextboxHelper.ClearTextButton="True"
Margin="88.694,36.96,0,0"
VerticalAlignment="Top"

0 comments on commit f6e14d0

Please sign in to comment.