Introduction
In my prevous article, I have demonstrated how to create Round Corner PasswordBox in WPF using XAML. In this article provides code snippet to create round corner PasswordBox using XML in WPF.
Code Snippet
<Window x:Class="RoundCornerPasswordBox.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Reound Corner Password Example" Height="350" Width="525">
<Window.Resources>
<Style TargetType="PasswordBox" x:Key="roundcornerpassword">
<Setter Property="PasswordChar" Value="●"/>
<Setter Property="KeyboardNavigation.TabNavigation" Value="None"/>
<Setter Property="BorderThickness" Value="1"/>
<Setter Property="HorizontalContentAlignment" Value="Left"/>
<Setter Property="Padding" Value="1"/>
<Setter Property="FocusVisualStyle" Value="{x:Null}"/>
<Setter Property="AllowDrop" Value="true"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="PasswordBox">
<Border CornerRadius="3" x:Name="Bd" Background="White" BorderBrush="Gray" BorderThickness="1" OpacityMask="{x:Null}">
<ScrollViewer SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" x:Name="PART_ContentHost" Template="{DynamicResource ScrollViewerControlTemplate1}"/>
</Border>
<ControlTemplate.Triggers>
<Trigger Property="IsEnabled" Value="false">
<Setter Property="Background" TargetName="Bd" Value="{DynamicResource {x:Static SystemColors.ControlBrushKey}}"/>
<Setter Property="Foreground" Value="{DynamicResource {x:Static SystemColors.GrayTextBrushKey}}"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
</Window.Resources>
<Grid>
<PasswordBox Style="{StaticResource roundcornerpassword}" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Width="200" Height="30" PasswordChar="*" Password="kailash" FontSize="20">
</PasswordBox>
</Grid>
</Window>
Summary
Hope above code snippet of this article may helpful to you
Thanks
Kailash Chandra Behera
Comments
Post a Comment