Skip to content

Commit 709abc4

Browse files
committed
PasswordBox: better DefaultCapsLockIcon, minor style fixes
1 parent 9f974d0 commit 709abc4

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

MahApps.Metro/Styles/Controls.PasswordBox.xaml

Lines changed: 26 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,30 @@
1010
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter" />
1111
<Converters:ThicknessToDoubleConverter x:Key="ThicknessToDoubleConverter" />
1212

13+
<Grid x:Key="DefaultCapsLockIcon"
14+
x:Shared="False"
15+
Background="{DynamicResource BlackBrush}"
16+
Opacity="0.8"
17+
Width="16"
18+
Height="16">
19+
<Grid.OpacityMask>
20+
<VisualBrush>
21+
<VisualBrush.Visual>
22+
<Canvas Width="24"
23+
Height="24">
24+
<Path Data="M13,14H11V10H13M13,18H11V16H13M1,21H23L12,2L1,21Z"
25+
Fill="Black" />
26+
</Canvas>
27+
</VisualBrush.Visual>
28+
</VisualBrush>
29+
</Grid.OpacityMask>
30+
</Grid>
31+
1332
<!--PasswordBox Style-->
1433
<Style TargetType="{x:Type PasswordBox}"
1534
x:Key="MetroPasswordBox">
35+
<Setter Property="Controls:PasswordBoxHelper.CapsLockIcon"
36+
Value="{StaticResource DefaultCapsLockIcon}" />
1637
<Setter Property="ContextMenu"
1738
Value="{DynamicResource TextBoxMetroContextMenu}" />
1839
<Setter Property="Controls:TextBoxHelper.IsMonitoring"
@@ -87,7 +108,6 @@
87108
<Grid Margin="2">
88109
<Grid.ColumnDefinitions>
89110
<ColumnDefinition Width="*" />
90-
<ColumnDefinition Width="{Binding ElementName=ButtonRow, Path=ActualHeight, Mode=OneWay}" />
91111
<ColumnDefinition Width="Auto" />
92112
<ColumnDefinition x:Name="ButtonColumn"
93113
Width="Auto" />
@@ -151,18 +171,19 @@
151171
FontFamily="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ButtonFontFamily), Mode=OneWay}"
152172
Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ButtonContent), Mode=OneWay}"
153173
Visibility="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:TextBoxHelper.ClearTextButton), Mode=OneWay, Converter={StaticResource BooleanToVisibilityConverter}}"
174+
Width="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:ControlsHelper.ButtonWidth), Mode=OneWay}"
154175
IsTabStop="False" />
155176
<ContentPresenter x:Name="PART_CapsLockIndicator"
156177
Grid.Row="0"
157178
Grid.Column="1"
158179
Grid.RowSpan="2"
180+
Margin="1"
159181
TextBlock.Foreground="{DynamicResource ControlsValidationBrush}"
160182
Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:PasswordBoxHelper.CapsLockIcon), Mode=TwoWay}"
161183
VerticalAlignment="Center"
162184
HorizontalAlignment="Right"
163185
ToolTip="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:PasswordBoxHelper.CapsLockWarningToolTip), Mode=OneWay}"
164-
Visibility="Collapsed"
165-
Width="16" />
186+
Visibility="Collapsed" />
166187
</Grid>
167188
<Rectangle x:Name="DisabledVisualElement"
168189
Stroke="{DynamicResource ControlsDisabledBrush}"
@@ -210,15 +231,6 @@
210231
</DataTrigger.ExitActions>
211232
</DataTrigger>
212233

213-
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Self}, Path=(Controls:TextBoxHelper.ClearTextButton)}"
214-
Value="False">
215-
<Setter TargetName="PART_ContentHost"
216-
Property="Grid.ColumnSpan"
217-
Value="2" />
218-
<Setter TargetName="Message"
219-
Property="Grid.ColumnSpan"
220-
Value="2" />
221-
</DataTrigger>
222234
<Trigger Property="IsMouseOver"
223235
Value="True">
224236
<Setter TargetName="FocusRectangle"
@@ -419,13 +431,13 @@
419431
Grid.Row="0"
420432
Grid.Column="1"
421433
Grid.RowSpan="2"
434+
Margin="1"
422435
TextBlock.Foreground="{DynamicResource ControlsValidationBrush}"
423436
Content="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:PasswordBoxHelper.CapsLockIcon), Mode=TwoWay}"
424437
VerticalAlignment="Center"
425438
HorizontalAlignment="Right"
426439
ToolTip="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=(Controls:PasswordBoxHelper.CapsLockWarningToolTip), Mode=OneWay}"
427-
Visibility="Collapsed"
428-
Width="16" />
440+
Visibility="Collapsed" />
429441
</Grid>
430442
<Rectangle x:Name="DisabledVisualElement"
431443
Stroke="{DynamicResource ControlsDisabledBrush}"

samples/MetroDemo/ExampleViews/TextExamples.xaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,10 +172,12 @@
172172
<Label Content="PasswordBox"
173173
Style="{DynamicResource DescriptionHeaderStyle}" />
174174
<PasswordBox Margin="0, 10, 0, 0"
175+
Controls:TextBoxHelper.Watermark="Password"
175176
Password="Password" />
176177
<PasswordBox Margin="0, 10, 0, 0"
178+
Controls:TextBoxHelper.Watermark="Password"
179+
Controls:TextBoxHelper.UseFloatingWatermark="True"
177180
Controls:TextBoxHelper.ClearTextButton="True"
178-
Controls:PasswordBoxHelper.CapsLockIcon="!"
179181
Controls:TextBoxHelper.ButtonCommand="{Binding TextBoxButtonCmd, Mode=OneWay}"
180182
Password="Password" />
181183
<PasswordBox Margin="0, 10, 0, 0"

0 commit comments

Comments
 (0)