I am trying to apply watermark on a PasswordBox
using XAML, it applied perfectly but not hiding the watermark when password is typed in.
Password watermark not hiding in picture:
My tried XAML style resource for PasswordBox
:
<Application.Resources>
<Style x:Key="PasswordStyle" TargetType="PasswordBox" >
<Setter Property="VerticalAlignment" Value="Center" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="PasswordBox">
<Border MinWidth="{TemplateBinding MinWidth}">
<Grid>
<StackPanel Margin="8">
<ScrollViewer x:Name="PART_ContentHost"/>
</StackPanel>
<StackPanel>
<TextBlock Name="PART_TempText" Text="Enter Password" Foreground="#807C7C"
Visibility="Collapsed" TextAlignment="Center" HorizontalAlignment="Center" Padding="8" />
</StackPanel>
</Grid>
</Border>
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding Password.Length, RelativeSource={RelativeSource Self}}" Value="0">
<Setter TargetName="PART_TempText" Property="Visibility" Value="Visible" />
</DataTrigger>
<DataTrigger Binding="{Binding Password.Length, RelativeSource={RelativeSource Self}}" Value="1">
<Setter TargetName="PART_TempText" Property="Visibility" Value="Collapsed" />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Application.Resources>
And the `PasswordBox` XAML code:
<PasswordBox Grid.Row="6" x:Name="txtPassword" HorizontalAlignment="Center" Width="200" HorizontalContentAlignment="Center" VerticalAlignment="Center" KeyUp="txtPassword_KeyUp"
Style="{StaticResource PasswordStyle}" />
I want to hide the watermark when user start typing in the `PasswordBox` using XAML.
You any help related to XAML will be appreciated!