Skip to content

Commit 1cb363b

Browse files
authored
Merge pull request #232 from GID0317/#231
Gallery Revamp: PasswordBox Page
2 parents 8c84efe + 6e59c50 commit 1cb363b

File tree

2 files changed

+73
-18
lines changed

2 files changed

+73
-18
lines changed
Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<ui:Page
1+
<ui:Page
22
x:Class="iNKORE.UI.WPF.Modern.Gallery.Pages.Controls.Windows.PasswordBoxPage"
33
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
44
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
@@ -10,27 +10,45 @@
1010
mc:Ignorable="d" Loaded="Page_Loaded">
1111
<ikw:SimpleStackPanel>
1212
<local:ControlExample x:Name="Example1" HeaderText="A simple PasswordBox.">
13-
<PasswordBox Width="300" />
13+
<StackPanel>
14+
<PasswordBox
15+
Width="300"
16+
HorizontalAlignment="Left"
17+
AutomationProperties.Name="Simple PasswordBox"
18+
PasswordChanged="PasswordBox_PasswordChanged" />
19+
<TextBlock
20+
x:Name="Control1Output"
21+
FontFamily="Global User Interface"
22+
Style="{StaticResource OutputTextBlockStyle}"
23+
Visibility="Collapsed" />
24+
</StackPanel>
1425
</local:ControlExample>
1526

1627
<local:ControlExample x:Name="Example2" HeaderText="A PasswordBox with header, placeholder text and custom character.">
1728
<PasswordBox
1829
x:Name="passwordBox"
1930
Width="300"
31+
HorizontalAlignment="Left"
2032
ui:ControlHelper.Header="Password"
2133
ui:ControlHelper.PlaceholderText="Enter your password"
22-
ui:PasswordBoxHelper.PasswordRevealMode="Hidden"
2334
PasswordChar="#" />
35+
</local:ControlExample>
2436

25-
<local:ControlExample.Options>
26-
<ikw:SimpleStackPanel Style="{StaticResource OptionsPanelStyle}">
27-
<ui:RadioButtons
28-
Header="PasswordRevealMode"
29-
ItemsSource="{Binding Source={x:Type ui:PasswordRevealMode}, Converter={StaticResource EnumValuesConverter}}"
30-
SelectedItem="{Binding ElementName=passwordBox, Path=(ui:PasswordBoxHelper.PasswordRevealMode)}"
31-
SelectionChanged="RadioButtons_SelectionChanged"/>
32-
</ikw:SimpleStackPanel>
33-
</local:ControlExample.Options>
37+
<local:ControlExample x:Name="Example3" HeaderText="A PasswordBox with reveal mode.">
38+
<StackPanel Orientation="Horizontal" VerticalAlignment="Center">
39+
<PasswordBox
40+
x:Name="passwordBoxWithReveal"
41+
Width="250"
42+
Margin="0,0,8,0"
43+
AutomationProperties.Name="Sample password box"
44+
ui:PasswordBoxHelper.PasswordRevealMode="Hidden" />
45+
<CheckBox
46+
x:Name="revealModeCheckBox"
47+
Content="Show password"
48+
IsChecked="False"
49+
Checked="RevealModeCheckbox_Changed"
50+
Unchecked="RevealModeCheckbox_Changed" />
51+
</StackPanel>
3452
</local:ControlExample>
3553
</ikw:SimpleStackPanel>
3654
</ui:Page>

source/iNKORE.UI.WPF.Modern.Gallery/Pages/Controls/Windows/PasswordBoxPage.xaml.cs

Lines changed: 43 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
using System;
1+
using System;
22
using System.Collections.Generic;
33
using System.Text;
44
using System.Windows;
@@ -10,6 +10,8 @@
1010
using System.Windows.Media.Imaging;
1111
using System.Windows.Navigation;
1212
using System.Windows.Shapes;
13+
using iNKORE.UI.WPF.Modern.Common;
14+
using iNKORE.UI.WPF.Modern.Controls;
1315
using iNKORE.UI.WPF.Modern.Controls.Helpers;
1416

1517
namespace iNKORE.UI.WPF.Modern.Gallery.Pages.Controls.Windows
@@ -29,6 +31,36 @@ private void Page_Loaded(object sender, RoutedEventArgs e)
2931
UpdateExampleCode();
3032
}
3133

34+
private void PasswordBox_PasswordChanged(object sender, RoutedEventArgs e)
35+
{
36+
if (sender is PasswordBox pb)
37+
{
38+
if (string.IsNullOrEmpty(pb.Password) || pb.Password == "Password")
39+
{
40+
Control1Output.Visibility = Visibility.Visible;
41+
Control1Output.Text = "'Password' is not allowed.";
42+
pb.Password = string.Empty;
43+
}
44+
else
45+
{
46+
Control1Output.Text = string.Empty;
47+
Control1Output.Visibility = Visibility.Collapsed;
48+
}
49+
}
50+
}
51+
52+
private void RevealModeCheckbox_Changed(object sender, RoutedEventArgs e)
53+
{
54+
if (revealModeCheckBox.IsChecked == true)
55+
{
56+
PasswordBoxHelper.SetPasswordRevealMode(passwordBoxWithReveal, PasswordRevealMode.Visible);
57+
}
58+
else
59+
{
60+
PasswordBoxHelper.SetPasswordRevealMode(passwordBoxWithReveal, PasswordRevealMode.Hidden);
61+
}
62+
}
63+
3264
private void RadioButtons_SelectionChanged(object sender, SelectionChangedEventArgs e)
3365
{
3466
UpdateExampleCode();
@@ -43,17 +75,22 @@ public void UpdateExampleCode()
4375

4476
Example1.Xaml = Example1Xaml;
4577
Example2.Xaml = Example2Xaml;
78+
Example3.Xaml = Example3Xaml;
4679
}
4780

4881
public string Example1Xaml => $@"
49-
<PasswordBox/>
82+
<PasswordBox Width=""300"" AutomationProperties.Name=""Simple PasswordBox""/>
5083
";
5184

5285
public string Example2Xaml => $@"
53-
<PasswordBox x:Name=""passwordBox""
54-
ui:ControlHelper.Header=""Password"" PasswordChar=""#""
55-
ui:ControlHelper.PlaceholderText=""Enter your password""
56-
ui:PasswordBoxHelper.PasswordRevealMode=""{PasswordBoxHelper.GetPasswordRevealMode(passwordBox)}"" />
86+
<PasswordBox x:Name=""passwordBox"" Width=""300"" ui:ControlHelper.Header=""Password"" ui:ControlHelper.PlaceholderText=""Enter your password"" PasswordChar=""#"" />
87+
";
88+
89+
public string Example3Xaml => $@"
90+
<PasswordBox x:Name=""passwordBoxWithReveal"" Width=""250"" Margin=""0,0,8,0""
91+
ui:PasswordBoxHelper.PasswordRevealMode=""Hidden"" AutomationProperties.Name=""Sample password box""/>
92+
<CheckBox x:Name=""revealModeCheckBox"" Content=""Show password"" IsChecked=""False""
93+
Checked=""RevealModeCheckbox_Changed"" Unchecked=""RevealModeCheckbox_Changed""/>
5794
";
5895

5996
#endregion

0 commit comments

Comments
 (0)