Skip to content

Commit 94b3974

Browse files
authored
Fixed AutomationProperties.Name for DatePicker Button (#10949)
* Added AutomationProperties.Name for DatePicker Button * Fixes DatePicker control to match the use of localized resource for ShowCalendar button name * Made Show Calendar button focusable
1 parent e93e3db commit 94b3974

File tree

5 files changed

+25
-30
lines changed

5 files changed

+25
-30
lines changed

src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Styles/DatePicker.xaml

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@
127127
<Setter Property="IsTodayHighlighted" Value="True" />
128128
<Setter Property="SelectedDateFormat" Value="Short" />
129129
<Setter Property="OverridesDefaultStyle" Value="True" />
130+
<Setter Property="KeyboardNavigation.TabNavigation" Value="Local" />
130131
<Setter Property="Template">
131132
<Setter.Value>
132133
<ControlTemplate TargetType="{x:Type DatePicker}">
@@ -148,8 +149,11 @@
148149
BorderThickness="{TemplateBinding BorderThickness}"
149150
Background="{TemplateBinding Background}"
150151
CornerRadius="{TemplateBinding Border.CornerRadius}">
151-
<ContentPresenter x:Name="GlyphElement"
152+
<TextBlock x:Name="GlyphElement"
152153
TextElement.Foreground="{TemplateBinding Foreground}"
154+
FontFamily="{DynamicResource SymbolThemeFontFamily}"
155+
FontSize="{DynamicResource DatePickerCalendarButtonIconSize}"
156+
Text="{StaticResource DatePickerCalendarGlyph}"
153157
VerticalAlignment="Center"
154158
HorizontalAlignment="Center" />
155159
</Border>
@@ -190,20 +194,15 @@
190194
<DatePickerTextBox x:Name="PART_TextBox"
191195
Padding="{TemplateBinding Padding}"
192196
HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
193-
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
197+
VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
198+
KeyboardNavigation.TabIndex="0" />
194199

195200
<Button x:Name="PART_Button"
196201
Grid.Column="1"
197202
VerticalAlignment="Stretch"
198203
Style="{StaticResource CalendarButtonStyle}"
199-
Focusable="False"
200-
MinWidth="30">
201-
<TextBlock FontFamily="{DynamicResource SymbolThemeFontFamily}"
202-
FontSize="{DynamicResource DatePickerCalendarButtonIconSize}"
203-
Text="{StaticResource DatePickerCalendarGlyph}"
204-
HorizontalAlignment="Center"
205-
VerticalAlignment="Center" />
206-
</Button>
204+
KeyboardNavigation.TabIndex="1"
205+
MinWidth="30" />
207206
</Grid>
208207

209208
<Popup

src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Themes/Fluent.Dark.xaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2560,6 +2560,7 @@
25602560
<Setter Property="IsTodayHighlighted" Value="True" />
25612561
<Setter Property="SelectedDateFormat" Value="Short" />
25622562
<Setter Property="OverridesDefaultStyle" Value="True" />
2563+
<Setter Property="KeyboardNavigation.TabNavigation" Value="Local" />
25632564
<Setter Property="Template">
25642565
<Setter.Value>
25652566
<ControlTemplate TargetType="{x:Type DatePicker}">
@@ -2576,7 +2577,7 @@
25762577
<Setter.Value>
25772578
<ControlTemplate TargetType="Button">
25782579
<Border x:Name="ButtonLayoutBorder" Margin="{DynamicResource DatePickerCalendarButtonMargin}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="{TemplateBinding Border.CornerRadius}">
2579-
<ContentPresenter x:Name="GlyphElement" TextElement.Foreground="{TemplateBinding Foreground}" VerticalAlignment="Center" HorizontalAlignment="Center" />
2580+
<TextBlock x:Name="GlyphElement" TextElement.Foreground="{TemplateBinding Foreground}" FontFamily="{DynamicResource SymbolThemeFontFamily}" FontSize="{DynamicResource DatePickerCalendarButtonIconSize}" Text="{StaticResource DatePickerCalendarGlyph}" VerticalAlignment="Center" HorizontalAlignment="Center" />
25802581
</Border>
25812582
<ControlTemplate.Triggers>
25822583
<Trigger Property="IsMouseOver" Value="True">
@@ -2604,10 +2605,8 @@
26042605
</Grid.ColumnDefinitions>
26052606
<Border x:Name="BorderElement" Grid.ColumnSpan="2" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="{TemplateBinding Border.CornerRadius}" MinHeight="32">
26062607
</Border>
2607-
<DatePickerTextBox x:Name="PART_TextBox" Padding="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
2608-
<Button x:Name="PART_Button" Grid.Column="1" VerticalAlignment="Stretch" Style="{StaticResource CalendarButtonStyle}" Focusable="False" MinWidth="30">
2609-
<TextBlock FontFamily="{DynamicResource SymbolThemeFontFamily}" FontSize="{DynamicResource DatePickerCalendarButtonIconSize}" Text="{StaticResource DatePickerCalendarGlyph}" HorizontalAlignment="Center" VerticalAlignment="Center" />
2610-
</Button>
2608+
<DatePickerTextBox x:Name="PART_TextBox" Padding="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" KeyboardNavigation.TabIndex="0" />
2609+
<Button x:Name="PART_Button" Grid.Column="1" VerticalAlignment="Stretch" Style="{StaticResource CalendarButtonStyle}" KeyboardNavigation.TabIndex="1" MinWidth="30" />
26112610
</Grid>
26122611
<Popup x:Name="PART_Popup" VerticalAlignment="Top" AllowsTransparency="True" Placement="Bottom" PlacementTarget="{Binding ElementName=PART_Root}" StaysOpen="False">
26132612
</Popup>

src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Themes/Fluent.HC.xaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2460,6 +2460,7 @@
24602460
<Setter Property="IsTodayHighlighted" Value="True" />
24612461
<Setter Property="SelectedDateFormat" Value="Short" />
24622462
<Setter Property="OverridesDefaultStyle" Value="True" />
2463+
<Setter Property="KeyboardNavigation.TabNavigation" Value="Local" />
24632464
<Setter Property="Template">
24642465
<Setter.Value>
24652466
<ControlTemplate TargetType="{x:Type DatePicker}">
@@ -2476,7 +2477,7 @@
24762477
<Setter.Value>
24772478
<ControlTemplate TargetType="Button">
24782479
<Border x:Name="ButtonLayoutBorder" Margin="{DynamicResource DatePickerCalendarButtonMargin}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="{TemplateBinding Border.CornerRadius}">
2479-
<ContentPresenter x:Name="GlyphElement" TextElement.Foreground="{TemplateBinding Foreground}" VerticalAlignment="Center" HorizontalAlignment="Center" />
2480+
<TextBlock x:Name="GlyphElement" TextElement.Foreground="{TemplateBinding Foreground}" FontFamily="{DynamicResource SymbolThemeFontFamily}" FontSize="{DynamicResource DatePickerCalendarButtonIconSize}" Text="{StaticResource DatePickerCalendarGlyph}" VerticalAlignment="Center" HorizontalAlignment="Center" />
24802481
</Border>
24812482
<ControlTemplate.Triggers>
24822483
<Trigger Property="IsMouseOver" Value="True">
@@ -2504,10 +2505,8 @@
25042505
</Grid.ColumnDefinitions>
25052506
<Border x:Name="BorderElement" Grid.ColumnSpan="2" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="{TemplateBinding Border.CornerRadius}" MinHeight="32">
25062507
</Border>
2507-
<DatePickerTextBox x:Name="PART_TextBox" Padding="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
2508-
<Button x:Name="PART_Button" Grid.Column="1" VerticalAlignment="Stretch" Style="{StaticResource CalendarButtonStyle}" Focusable="False" MinWidth="30">
2509-
<TextBlock FontFamily="{DynamicResource SymbolThemeFontFamily}" FontSize="{DynamicResource DatePickerCalendarButtonIconSize}" Text="{StaticResource DatePickerCalendarGlyph}" HorizontalAlignment="Center" VerticalAlignment="Center" />
2510-
</Button>
2508+
<DatePickerTextBox x:Name="PART_TextBox" Padding="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" KeyboardNavigation.TabIndex="0" />
2509+
<Button x:Name="PART_Button" Grid.Column="1" VerticalAlignment="Stretch" Style="{StaticResource CalendarButtonStyle}" KeyboardNavigation.TabIndex="1" MinWidth="30" />
25112510
</Grid>
25122511
<Popup x:Name="PART_Popup" VerticalAlignment="Top" AllowsTransparency="True" Placement="Bottom" PlacementTarget="{Binding ElementName=PART_Root}" StaysOpen="False">
25132512
</Popup>

src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Themes/Fluent.Light.xaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2575,6 +2575,7 @@
25752575
<Setter Property="IsTodayHighlighted" Value="True" />
25762576
<Setter Property="SelectedDateFormat" Value="Short" />
25772577
<Setter Property="OverridesDefaultStyle" Value="True" />
2578+
<Setter Property="KeyboardNavigation.TabNavigation" Value="Local" />
25782579
<Setter Property="Template">
25792580
<Setter.Value>
25802581
<ControlTemplate TargetType="{x:Type DatePicker}">
@@ -2591,7 +2592,7 @@
25912592
<Setter.Value>
25922593
<ControlTemplate TargetType="Button">
25932594
<Border x:Name="ButtonLayoutBorder" Margin="{DynamicResource DatePickerCalendarButtonMargin}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="{TemplateBinding Border.CornerRadius}">
2594-
<ContentPresenter x:Name="GlyphElement" TextElement.Foreground="{TemplateBinding Foreground}" VerticalAlignment="Center" HorizontalAlignment="Center" />
2595+
<TextBlock x:Name="GlyphElement" TextElement.Foreground="{TemplateBinding Foreground}" FontFamily="{DynamicResource SymbolThemeFontFamily}" FontSize="{DynamicResource DatePickerCalendarButtonIconSize}" Text="{StaticResource DatePickerCalendarGlyph}" VerticalAlignment="Center" HorizontalAlignment="Center" />
25952596
</Border>
25962597
<ControlTemplate.Triggers>
25972598
<Trigger Property="IsMouseOver" Value="True">
@@ -2619,10 +2620,8 @@
26192620
</Grid.ColumnDefinitions>
26202621
<Border x:Name="BorderElement" Grid.ColumnSpan="2" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="{TemplateBinding Border.CornerRadius}" MinHeight="32">
26212622
</Border>
2622-
<DatePickerTextBox x:Name="PART_TextBox" Padding="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
2623-
<Button x:Name="PART_Button" Grid.Column="1" VerticalAlignment="Stretch" Style="{StaticResource CalendarButtonStyle}" Focusable="False" MinWidth="30">
2624-
<TextBlock FontFamily="{DynamicResource SymbolThemeFontFamily}" FontSize="{DynamicResource DatePickerCalendarButtonIconSize}" Text="{StaticResource DatePickerCalendarGlyph}" HorizontalAlignment="Center" VerticalAlignment="Center" />
2625-
</Button>
2623+
<DatePickerTextBox x:Name="PART_TextBox" Padding="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" KeyboardNavigation.TabIndex="0" />
2624+
<Button x:Name="PART_Button" Grid.Column="1" VerticalAlignment="Stretch" Style="{StaticResource CalendarButtonStyle}" KeyboardNavigation.TabIndex="1" MinWidth="30" />
26262625
</Grid>
26272626
<Popup x:Name="PART_Popup" VerticalAlignment="Top" AllowsTransparency="True" Placement="Bottom" PlacementTarget="{Binding ElementName=PART_Root}" StaysOpen="False">
26282627
</Popup>

src/Microsoft.DotNet.Wpf/src/Themes/PresentationFramework.Fluent/Themes/Fluent.xaml

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1758,6 +1758,7 @@
17581758
<Setter Property="IsTodayHighlighted" Value="True" />
17591759
<Setter Property="SelectedDateFormat" Value="Short" />
17601760
<Setter Property="OverridesDefaultStyle" Value="True" />
1761+
<Setter Property="KeyboardNavigation.TabNavigation" Value="Local" />
17611762
<Setter Property="Template">
17621763
<Setter.Value>
17631764
<ControlTemplate TargetType="{x:Type DatePicker}">
@@ -1774,7 +1775,7 @@
17741775
<Setter.Value>
17751776
<ControlTemplate TargetType="Button">
17761777
<Border x:Name="ButtonLayoutBorder" Margin="{DynamicResource DatePickerCalendarButtonMargin}" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="{TemplateBinding Border.CornerRadius}">
1777-
<ContentPresenter x:Name="GlyphElement" TextElement.Foreground="{TemplateBinding Foreground}" VerticalAlignment="Center" HorizontalAlignment="Center" />
1778+
<TextBlock x:Name="GlyphElement" TextElement.Foreground="{TemplateBinding Foreground}" FontFamily="{DynamicResource SymbolThemeFontFamily}" FontSize="{DynamicResource DatePickerCalendarButtonIconSize}" Text="{StaticResource DatePickerCalendarGlyph}" VerticalAlignment="Center" HorizontalAlignment="Center" />
17781779
</Border>
17791780
<ControlTemplate.Triggers>
17801781
<Trigger Property="IsMouseOver" Value="True">
@@ -1802,10 +1803,8 @@
18021803
</Grid.ColumnDefinitions>
18031804
<Border x:Name="BorderElement" Grid.ColumnSpan="2" BorderBrush="{TemplateBinding BorderBrush}" BorderThickness="{TemplateBinding BorderThickness}" Background="{TemplateBinding Background}" CornerRadius="{TemplateBinding Border.CornerRadius}" MinHeight="32">
18041805
</Border>
1805-
<DatePickerTextBox x:Name="PART_TextBox" Padding="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
1806-
<Button x:Name="PART_Button" Grid.Column="1" VerticalAlignment="Stretch" Style="{StaticResource CalendarButtonStyle}" Focusable="False" MinWidth="30">
1807-
<TextBlock FontFamily="{DynamicResource SymbolThemeFontFamily}" FontSize="{DynamicResource DatePickerCalendarButtonIconSize}" Text="{StaticResource DatePickerCalendarGlyph}" HorizontalAlignment="Center" VerticalAlignment="Center" />
1808-
</Button>
1806+
<DatePickerTextBox x:Name="PART_TextBox" Padding="{TemplateBinding Padding}" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}" KeyboardNavigation.TabIndex="0" />
1807+
<Button x:Name="PART_Button" Grid.Column="1" VerticalAlignment="Stretch" Style="{StaticResource CalendarButtonStyle}" KeyboardNavigation.TabIndex="1" MinWidth="30" />
18091808
</Grid>
18101809
<Popup x:Name="PART_Popup" VerticalAlignment="Top" AllowsTransparency="True" Placement="Bottom" PlacementTarget="{Binding ElementName=PART_Root}" StaysOpen="False">
18111810
</Popup>

0 commit comments

Comments
 (0)