Skip to content

Commit 2a62378

Browse files
Respect MaxLength of PasswordBox using a template binding (#2999)
The reveal style TextBox showing the cleartext password is now limited to the same MaxLength as the "parent" PasswordBox.
1 parent 8b59f58 commit 2a62378

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

MaterialDesignThemes.UITests/WPF/PasswordBoxes/PasswordBoxTests.cs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,6 +163,28 @@ public async Task PasswordBox_WithBoundPasswordProperty_RespectsBinding()
163163
Assert.Equal("2", password2);
164164

165165
recorder.Success();
166-
}
166+
}
167+
168+
[Fact]
169+
[Description("Issue 2998")]
170+
public async Task PasswordBox_WithRevealStyle_RespectsMaxLength()
171+
{
172+
await using var recorder = new TestRecorder(App);
173+
174+
var grid = await LoadXaml<Grid>(@"
175+
<Grid Margin=""30"">
176+
<PasswordBox MaxLength=""5"" Style=""{StaticResource MaterialDesignFloatingHintRevealPasswordBox}"" />
177+
</Grid>");
178+
var passwordBox = await grid.GetElement<PasswordBox>("/PasswordBox");
179+
var revealPasswordTextBox = await passwordBox.GetElement<TextBox>("RevealPasswordTextBox");
180+
181+
int maxLength1 = await passwordBox.GetMaxLength();
182+
int maxLength2 = await revealPasswordTextBox.GetMaxLength();
183+
184+
// Assert
185+
Assert.Equal(maxLength1, maxLength2);
186+
187+
recorder.Success();
188+
}
167189
}
168190
}

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.PasswordBox.xaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -634,6 +634,7 @@
634634
Padding="{Binding ElementName=PART_ContentHost, Path=Padding}"
635635
CaretBrush="{TemplateBinding CaretBrush}"
636636
Cursor="{TemplateBinding Cursor, Converter={StaticResource IBeamCursorConverter}}"
637+
MaxLength="{TemplateBinding MaxLength}"
637638
Foreground="{TemplateBinding Foreground}"
638639
SelectionBrush="{TemplateBinding SelectionBrush}"
639640
SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"

0 commit comments

Comments
 (0)