Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <Style x:Key="HintedPasswordBox" TargetType="{x:Type PasswordBox}">
- <Setter Property="PasswordChar" Value="●" />
- <Setter Property="Background" Value="{DynamicResource TextBox.Static.Background}" />
- <Setter Property="BorderBrush" Value="{DynamicResource TextBox.Static.Border}" />
- <Setter Property="Foreground" Value="{DynamicResource AREghZyBrush.Foreground.Static}" />
- <Setter Property="BorderThickness" Value="1" />
- <Setter Property="KeyboardNavigation.TabNavigation" Value="None" />
- <Setter Property="HorizontalContentAlignment" Value="Left" />
- <Setter Property="FocusVisualStyle" Value="{x:Null}" />
- <Setter Property="AllowDrop" Value="true" />
- <Setter Property="ScrollViewer.PanningMode" Value="VerticalFirst" />
- <Setter Property="Stylus.IsFlicksEnabled" Value="False" />
- <Setter Property="ap:PasswordAttachedProperty.ListenToLength" Value="True"/>
- <Setter Property="Template">
- <Setter.Value>
- <ControlTemplate TargetType="{x:Type PasswordBox}">
- <Grid>
- <Border x:Name="border" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" SnapsToDevicePixels="True">
- <ScrollViewer x:Name="PART_ContentHost" Focusable="false" HorizontalScrollBarVisibility="Hidden" VerticalScrollBarVisibility="Hidden" />
- </Border>
- <TextBlock IsHitTestVisible="False"
- Text="{TemplateBinding Tag}"
- x:Name="PART_Placeholder"
- FontFamily="{TemplateBinding FontFamily}"
- FontSize="{TemplateBinding FontSize}"
- Margin="3 0 0 0"
- Padding="{TemplateBinding Padding}"
- VerticalAlignment="Center"
- HorizontalAlignment="{TemplateBinding HorizontalAlignment}"
- Foreground="{DynamicResource AREghZyBrush.Foreground.Disabled}">
- <TextBlock.Style>
- <Style TargetType="{x:Type TextBlock}">
- <Setter Property="Visibility" Value="Collapsed"/>
- <Style.Triggers>
- <DataTrigger Binding="{Binding (ap:PasswordAttachedProperty.InputLength), RelativeSource={RelativeSource TemplatedParent}}" Value="0">
- <Setter Property="Visibility" Value="Visible"/>
- </DataTrigger>
- <MultiDataTrigger>
- <MultiDataTrigger.Conditions>
- <Condition Binding="{Binding IsFocused, RelativeSource={RelativeSource TemplatedParent}}" Value="True"/>
- <Condition Binding="{Binding (ap:TextHinting.ShowWhenFocused), RelativeSource={RelativeSource TemplatedParent}}" Value="False"/>
- </MultiDataTrigger.Conditions>
- <MultiDataTrigger.Setters>
- <Setter Property="Visibility" Value="Collapsed"/>
- </MultiDataTrigger.Setters>
- </MultiDataTrigger>
- </Style.Triggers>
- </Style>
- </TextBlock.Style>
- </TextBlock>
- </Grid>
- <ControlTemplate.Triggers>
- <Trigger Property="IsEnabled" Value="false">
- <Setter Property="Opacity" TargetName="border" Value="0.56" />
- </Trigger>
- <Trigger Property="IsMouseOver" Value="true">
- <Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource TextBox.MouseOver.Border}" />
- </Trigger>
- <Trigger Property="IsKeyboardFocused" Value="true">
- <Setter Property="BorderBrush" TargetName="border" Value="{DynamicResource TextBox.Focus.Border}" />
- </Trigger>
- </ControlTemplate.Triggers>
- </ControlTemplate>
- </Setter.Value>
- </Setter>
- <Style.Triggers>
- <MultiTrigger>
- <MultiTrigger.Conditions>
- <Condition Property="IsInactiveSelectionHighlightEnabled" Value="true" />
- <Condition Property="IsSelectionActive" Value="false" />
- </MultiTrigger.Conditions>
- <Setter Property="SelectionBrush" Value="{DynamicResource TextBox.Selection.Inactive}" />
- </MultiTrigger>
- </Style.Triggers>
- </Style>
- public class PasswordAttachedProperty {
- public static readonly DependencyProperty ListenToLengthProperty =
- DependencyProperty.RegisterAttached(
- "ListenToLength",
- typeof(bool),
- typeof(PasswordAttachedProperty),
- new FrameworkPropertyMetadata(false, PropertyChangedCallback));
- private static void PropertyChangedCallback(DependencyObject d, DependencyPropertyChangedEventArgs e) {
- if (e.NewValue == e.OldValue) {
- return;
- }
- if (d is PasswordBox box) {
- if ((bool) e.NewValue) {
- // just in case...
- box.PasswordChanged -= BoxOnPasswordChanged;
- box.PasswordChanged += BoxOnPasswordChanged;
- }
- else {
- box.PasswordChanged -= BoxOnPasswordChanged;
- }
- }
- else {
- throw new Exception("DependencyObject is not a password box. It is '" + (d == null ? "null" : d.GetType().Name) + '\'');
- }
- }
- public static readonly DependencyProperty InputLengthProperty =
- DependencyProperty.RegisterAttached(
- "InputLength",
- typeof(int),
- typeof(PasswordAttachedProperty),
- new FrameworkPropertyMetadata(0));
- public static bool GetListenToLength(PasswordBox box) {
- return (bool) box.GetValue(ListenToLengthProperty);
- }
- public static void SetListenToLength(PasswordBox box, bool value) {
- box.SetValue(ListenToLengthProperty, value);
- }
- public static int GetInputLength(PasswordBox box) {
- return (int) box.GetValue(InputLengthProperty);
- }
- public static void SetInputLength(PasswordBox box, int value) {
- box.SetValue(InputLengthProperty, value);
- }
- private static void BoxOnPasswordChanged(object sender, RoutedEventArgs e) {
- SetInputLength((PasswordBox) sender, ((PasswordBox) sender).SecurePassword.Length);
- }
- }
- public static class TextHinting {
- public static readonly DependencyProperty ShowWhenFocusedProperty =
- DependencyProperty.RegisterAttached(
- "ShowWhenFocused",
- typeof(bool),
- typeof(TextHinting),
- new FrameworkPropertyMetadata(false));
- public static void SetShowWhenFocused(Control control, bool value) {
- if (control is TextBoxBase || control is PasswordBox) {
- control.SetValue(ShowWhenFocusedProperty, value);
- }
- throw new ArgumentException("Control was not a textbox", "control");
- }
- public static bool GetShowWhenFocused(Control control) {
- if (control is TextBoxBase || control is PasswordBox) {
- return (bool) control.GetValue(ShowWhenFocusedProperty);
- }
- throw new ArgumentException("Control was not a textbox", "control");
- }
- }
- https://github.com/AngryCarrot789/REghZyAccountManagerV6
Add Comment
Please, Sign In to add comment