Skip to content

Commit 06f781a

Browse files
Add leading icon support in PasswordBox variants (#3274)
1 parent 007eed3 commit 06f781a

File tree

1 file changed

+65
-4
lines changed

1 file changed

+65
-4
lines changed

MaterialDesignThemes.Wpf/Themes/MaterialDesignTheme.PasswordBox.xaml

Lines changed: 65 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
1+
<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
22
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
33
xmlns:behaviors="http://schemas.microsoft.com/xaml/behaviors"
44
xmlns:converters="clr-namespace:MaterialDesignThemes.Wpf.Converters"
@@ -22,6 +22,18 @@
2222
<converters:CursorConverter x:Key="ArrowCursorConverter" FallbackCursor="Arrow" />
2323
<converters:CursorConverter x:Key="IBeamCursorConverter" FallbackCursor="IBeam" />
2424
<converters:ThicknessCloneConverter x:Key="HelperTextMarginConverter" CloneEdges="Left" />
25+
<converters:ThicknessCloneConverter x:Key="DefaultOrFilledStyleLeadingIconMarginConverterTop"
26+
AdditionalOffsetTop="-2"
27+
CloneEdges="Top"
28+
FixedRight="6" />
29+
<converters:ThicknessCloneConverter x:Key="DefaultOrFilledStyleLeadingIconMarginConverterCenter"
30+
AdditionalOffsetTop="-12"
31+
CloneEdges="Top"
32+
FixedRight="6" />
33+
<converters:ThicknessCloneConverter x:Key="DefaultOrFilledStyleLeadingIconMarginConverterBottom"
34+
CloneEdges="Top"
35+
FixedBottom="-2"
36+
FixedRight="6" />
2537
<converters:ThicknessCloneConverter x:Key="DefaultOrFilledStyleTrailingIconMarginConverterTop"
2638
AdditionalOffsetTop="-2"
2739
CloneEdges="Top" />
@@ -31,6 +43,19 @@
3143
<converters:ThicknessCloneConverter x:Key="DefaultOrFilledStyleTrailingIconMarginConverterBottom"
3244
CloneEdges="Top"
3345
FixedBottom="-2" />
46+
<converters:ThicknessCloneConverter x:Key="OutlinedStyleLeadingIconMarginConverterTop"
47+
AdditionalOffsetTop="-2"
48+
CloneEdges="Top"
49+
FixedRight="6" />
50+
<converters:ThicknessCloneConverter x:Key="OutlinedStyleLeadingIconMarginConverterCenter"
51+
AdditionalOffsetTop="0"
52+
CloneEdges="Top"
53+
FixedRight="6" />
54+
<converters:ThicknessCloneConverter x:Key="OutlinedStyleLeadingIconMarginConverterBottom"
55+
AdditionalOffsetTop="0"
56+
CloneEdges="Top"
57+
FixedBottom="-2"
58+
FixedRight="6" />
3459
<converters:ThicknessCloneConverter x:Key="OutlinedStyleTrailingIconMarginConverterTop"
3560
AdditionalOffsetTop="-2"
3661
CloneEdges="Top" />
@@ -41,6 +66,8 @@
4166
AdditionalOffsetTop="0"
4267
CloneEdges="Top"
4368
FixedBottom="-2" />
69+
70+
4471
<wpf:VerticalAlignmentConverter x:Key="VerticalAlignmentConverter" />
4572
<converters:NullableToVisibilityConverter x:Key="NullableToVisibilityConverter" />
4673

@@ -156,10 +183,21 @@
156183
SnapsToDevicePixels="True">
157184
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
158185
<Grid.ColumnDefinitions>
186+
<ColumnDefinition Width="Auto" />
159187
<ColumnDefinition />
160188
<ColumnDefinition Width="Auto" />
161189
</Grid.ColumnDefinitions>
190+
<wpf:PackIcon x:Name="LeadingPackIcon"
191+
Grid.Column="0"
192+
Width="{TemplateBinding wpf:TextFieldAssist.LeadingIconSize}"
193+
Height="{TemplateBinding wpf:TextFieldAssist.LeadingIconSize}"
194+
Margin="0,0,6,0"
195+
VerticalAlignment="{TemplateBinding VerticalContentAlignment, Converter={StaticResource VerticalAlignmentConverter}}"
196+
Kind="{TemplateBinding wpf:TextFieldAssist.LeadingIcon}"
197+
Opacity="{TemplateBinding wpf:HintAssist.HintOpacity}"
198+
Visibility="{TemplateBinding wpf:TextFieldAssist.HasLeadingIcon, Converter={StaticResource BooleanToVisibilityConverter}}" />
162199
<Grid x:Name="grid"
200+
Grid.Column="1"
163201
MinWidth="1"
164202
HorizontalAlignment="Stretch"
165203
VerticalAlignment="Stretch">
@@ -220,7 +258,7 @@
220258
Visibility="{TemplateBinding wpf:TextFieldAssist.SuffixText, Converter={StaticResource NullableToVisibilityConverter}}" />
221259
</Grid>
222260
<Button x:Name="PART_ClearButton"
223-
Grid.Column="1"
261+
Grid.Column="2"
224262
Height="Auto"
225263
Padding="2,0,0,0"
226264
VerticalAlignment="{TemplateBinding VerticalContentAlignment, Converter={StaticResource VerticalAlignmentConverter}}"
@@ -310,20 +348,23 @@
310348
</MultiTrigger.Conditions>
311349
<Setter TargetName="Hint" Property="InitialVerticalOffset" Value="-6" />
312350
<Setter TargetName="PART_ClearButton" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource DefaultOrFilledStyleTrailingIconMarginConverterCenter}}" />
351+
<Setter TargetName="LeadingPackIcon" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource DefaultOrFilledStyleLeadingIconMarginConverterCenter}}" />
313352
</MultiTrigger>
314353
<MultiTrigger>
315354
<MultiTrigger.Conditions>
316355
<Condition Property="wpf:TextFieldAssist.HasOutlinedTextField" Value="False" />
317356
<Condition SourceName="PART_ClearButton" Property="VerticalAlignment" Value="Top" />
318357
</MultiTrigger.Conditions>
319358
<Setter TargetName="PART_ClearButton" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource DefaultOrFilledStyleTrailingIconMarginConverterTop}}" />
359+
<Setter TargetName="LeadingPackIcon" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource DefaultOrFilledStyleLeadingIconMarginConverterTop}}" />
320360
</MultiTrigger>
321361
<MultiTrigger>
322362
<MultiTrigger.Conditions>
323363
<Condition Property="wpf:TextFieldAssist.HasOutlinedTextField" Value="False" />
324364
<Condition SourceName="PART_ClearButton" Property="VerticalAlignment" Value="Bottom" />
325365
</MultiTrigger.Conditions>
326366
<Setter TargetName="PART_ClearButton" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource DefaultOrFilledStyleTrailingIconMarginConverterBottom}}" />
367+
<Setter TargetName="LeadingPackIcon" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource DefaultOrFilledStyleLeadingIconMarginConverterBottom}}" />
327368
</MultiTrigger>
328369

329370
<!-- Icon margins adhering to VerticalContentAlignment for outlined style -->
@@ -333,20 +374,23 @@
333374
<Condition SourceName="PART_ClearButton" Property="VerticalAlignment" Value="Center" />
334375
</MultiTrigger.Conditions>
335376
<Setter TargetName="PART_ClearButton" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource OutlinedStyleTrailingIconMarginConverterCenter}}" />
377+
<Setter TargetName="LeadingPackIcon" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource OutlinedStyleLeadingIconMarginConverterCenter}}" />
336378
</MultiTrigger>
337379
<MultiTrigger>
338380
<MultiTrigger.Conditions>
339381
<Condition Property="wpf:TextFieldAssist.HasOutlinedTextField" Value="True" />
340382
<Condition SourceName="PART_ClearButton" Property="VerticalAlignment" Value="Top" />
341383
</MultiTrigger.Conditions>
342384
<Setter TargetName="PART_ClearButton" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource OutlinedStyleTrailingIconMarginConverterTop}}" />
385+
<Setter TargetName="LeadingPackIcon" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource OutlinedStyleLeadingIconMarginConverterTop}}" />
343386
</MultiTrigger>
344387
<MultiTrigger>
345388
<MultiTrigger.Conditions>
346389
<Condition Property="wpf:TextFieldAssist.HasOutlinedTextField" Value="True" />
347390
<Condition SourceName="PART_ClearButton" Property="VerticalAlignment" Value="Bottom" />
348391
</MultiTrigger.Conditions>
349392
<Setter TargetName="PART_ClearButton" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource OutlinedStyleTrailingIconMarginConverterBottom}}" />
393+
<Setter TargetName="LeadingPackIcon" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource OutlinedStyleLeadingIconMarginConverterBottom}}" />
350394
</MultiTrigger>
351395

352396
<Trigger Property="wpf:TextFieldAssist.HasFilledTextField" Value="True">
@@ -680,11 +724,22 @@
680724
SnapsToDevicePixels="True">
681725
<Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch">
682726
<Grid.ColumnDefinitions>
727+
<ColumnDefinition Width="Auto" />
683728
<ColumnDefinition Width="*" />
684729
<ColumnDefinition Width="Auto" />
685730
<ColumnDefinition Width="Auto" />
686731
</Grid.ColumnDefinitions>
732+
<wpf:PackIcon x:Name="LeadingPackIcon"
733+
Grid.Column="0"
734+
Width="{TemplateBinding wpf:TextFieldAssist.LeadingIconSize}"
735+
Height="{TemplateBinding wpf:TextFieldAssist.LeadingIconSize}"
736+
Margin="0,0,6,0"
737+
VerticalAlignment="{TemplateBinding VerticalContentAlignment, Converter={StaticResource VerticalAlignmentConverter}}"
738+
Kind="{TemplateBinding wpf:TextFieldAssist.LeadingIcon}"
739+
Opacity="{TemplateBinding wpf:HintAssist.HintOpacity}"
740+
Visibility="{TemplateBinding wpf:TextFieldAssist.HasLeadingIcon, Converter={StaticResource BooleanToVisibilityConverter}}" />
687741
<Grid x:Name="grid"
742+
Grid.Column="1"
688743
MinWidth="1"
689744
HorizontalAlignment="Stretch"
690745
VerticalAlignment="Stretch">
@@ -774,7 +829,7 @@
774829
Visibility="{TemplateBinding wpf:TextFieldAssist.SuffixText, Converter={StaticResource NullableToVisibilityConverter}}" />
775830
</Grid>
776831
<ToggleButton x:Name="RevealPasswordButton"
777-
Grid.Column="1"
832+
Grid.Column="2"
778833
Height="Auto"
779834
Padding="2,0,0,0"
780835
VerticalAlignment="{TemplateBinding VerticalContentAlignment, Converter={StaticResource VerticalAlignmentConverter}}"
@@ -785,7 +840,7 @@
785840
Foreground="{Binding ElementName=PART_ClearButton, Path=Foreground}" />
786841
</ToggleButton>
787842
<Button x:Name="PART_ClearButton"
788-
Grid.Column="2"
843+
Grid.Column="3"
789844
Height="Auto"
790845
Padding="2,0,0,0"
791846
VerticalAlignment="{TemplateBinding VerticalContentAlignment, Converter={StaticResource VerticalAlignmentConverter}}"
@@ -876,6 +931,7 @@
876931
<Setter TargetName="Hint" Property="InitialVerticalOffset" Value="-6" />
877932
<Setter TargetName="PART_ClearButton" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource DefaultOrFilledStyleTrailingIconMarginConverterCenter}}" />
878933
<Setter TargetName="RevealPasswordButton" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource DefaultOrFilledStyleTrailingIconMarginConverterCenter}}" />
934+
<Setter TargetName="LeadingPackIcon" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource DefaultOrFilledStyleLeadingIconMarginConverterCenter}}" />
879935
</MultiTrigger>
880936
<MultiTrigger>
881937
<MultiTrigger.Conditions>
@@ -884,6 +940,7 @@
884940
</MultiTrigger.Conditions>
885941
<Setter TargetName="PART_ClearButton" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource DefaultOrFilledStyleTrailingIconMarginConverterTop}}" />
886942
<Setter TargetName="RevealPasswordButton" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource DefaultOrFilledStyleTrailingIconMarginConverterTop}}" />
943+
<Setter TargetName="LeadingPackIcon" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource DefaultOrFilledStyleLeadingIconMarginConverterTop}}" />
887944
</MultiTrigger>
888945
<MultiTrigger>
889946
<MultiTrigger.Conditions>
@@ -892,6 +949,7 @@
892949
</MultiTrigger.Conditions>
893950
<Setter TargetName="PART_ClearButton" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource DefaultOrFilledStyleTrailingIconMarginConverterBottom}}" />
894951
<Setter TargetName="RevealPasswordButton" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource DefaultOrFilledStyleTrailingIconMarginConverterBottom}}" />
952+
<Setter TargetName="LeadingPackIcon" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource DefaultOrFilledStyleLeadingIconMarginConverterBottom}}" />
895953
</MultiTrigger>
896954

897955
<!-- Icon margins adhering to VerticalContentAlignment for outlined style -->
@@ -902,6 +960,7 @@
902960
</MultiTrigger.Conditions>
903961
<Setter TargetName="PART_ClearButton" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource OutlinedStyleTrailingIconMarginConverterCenter}}" />
904962
<Setter TargetName="RevealPasswordButton" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource OutlinedStyleTrailingIconMarginConverterCenter}}" />
963+
<Setter TargetName="LeadingPackIcon" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource OutlinedStyleLeadingIconMarginConverterCenter}}" />
905964
</MultiTrigger>
906965
<MultiTrigger>
907966
<MultiTrigger.Conditions>
@@ -910,6 +969,7 @@
910969
</MultiTrigger.Conditions>
911970
<Setter TargetName="PART_ClearButton" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource OutlinedStyleTrailingIconMarginConverterTop}}" />
912971
<Setter TargetName="RevealPasswordButton" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource OutlinedStyleTrailingIconMarginConverterTop}}" />
972+
<Setter TargetName="LeadingPackIcon" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource OutlinedStyleLeadingIconMarginConverterTop}}" />
913973
</MultiTrigger>
914974
<MultiTrigger>
915975
<MultiTrigger.Conditions>
@@ -918,6 +978,7 @@
918978
</MultiTrigger.Conditions>
919979
<Setter TargetName="PART_ClearButton" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource OutlinedStyleTrailingIconMarginConverterBottom}}" />
920980
<Setter TargetName="RevealPasswordButton" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource OutlinedStyleTrailingIconMarginConverterBottom}}" />
981+
<Setter TargetName="LeadingPackIcon" Property="Margin" Value="{Binding ElementName=grid, Path=Margin, Converter={StaticResource OutlinedStyleLeadingIconMarginConverterBottom}}" />
921982
</MultiTrigger>
922983

923984
<Trigger Property="wpf:TextFieldAssist.HasFilledTextField" Value="True">

0 commit comments

Comments
 (0)