Skip to content

Commit a54d5b8

Browse files
committed
Improve ButtonPopup accessibility and code formatting
Refactored the `VerticalStackLayout.Resources` section in `ButtonPopup.xaml` for better readability and consistency. Added a `Loaded` event handler (`Label_Loaded`) to the `Label` with the `Title` style to set semantic focus on load, enhancing accessibility. Implemented the `Label_Loaded` method in `ButtonPopup.xaml.cs` to handle this functionality.
1 parent 6cc673d commit a54d5b8

File tree

2 files changed

+37
-29
lines changed

2 files changed

+37
-29
lines changed

samples/CommunityToolkit.Maui.Sample/Views/Popups/ButtonPopup.xaml

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -6,37 +6,37 @@
66
xmlns:mct="http://schemas.microsoft.com/dotnet/2022/maui/toolkit"
77
BackgroundColor="LightCoral">
88

9-
<VerticalStackLayout Spacing="6">
10-
<VerticalStackLayout.Resources>
11-
<ResourceDictionary>
12-
<Style x:Key="Title" TargetType="Label">
13-
<Setter Property="FontSize" Value="26" />
14-
<Setter Property="FontAttributes" Value="Bold" />
15-
<Setter Property="TextColor" Value="#000" />
16-
<Setter Property="VerticalTextAlignment" Value="Center" />
17-
<Setter Property="HorizontalTextAlignment" Value="Center" />
18-
</Style>
19-
<Style x:Key="Divider" TargetType="BoxView">
20-
<Setter Property="HeightRequest" Value="1" />
21-
<Setter Property="Margin" Value="50, 12" />
22-
<Setter Property="Color" Value="#c3c3c3" />
23-
</Style>
24-
<Style x:Key="Content" TargetType="Label">
25-
<Setter Property="HorizontalTextAlignment" Value="Start" />
26-
<Setter Property="VerticalTextAlignment" Value="Center" />
27-
</Style>
28-
<Style x:Key="ConfirmButton" TargetType="Button">
29-
<Setter Property="VerticalOptions" Value="End" />
30-
</Style>
31-
</ResourceDictionary>
32-
</VerticalStackLayout.Resources>
9+
<VerticalStackLayout Spacing="6">
10+
<VerticalStackLayout.Resources>
11+
<ResourceDictionary>
12+
<Style x:Key="Title" TargetType="Label">
13+
<Setter Property="FontSize" Value="26" />
14+
<Setter Property="FontAttributes" Value="Bold" />
15+
<Setter Property="TextColor" Value="#000" />
16+
<Setter Property="VerticalTextAlignment" Value="Center" />
17+
<Setter Property="HorizontalTextAlignment" Value="Center" />
18+
</Style>
19+
<Style x:Key="Divider" TargetType="BoxView">
20+
<Setter Property="HeightRequest" Value="1" />
21+
<Setter Property="Margin" Value="50, 12" />
22+
<Setter Property="Color" Value="#c3c3c3" />
23+
</Style>
24+
<Style x:Key="Content" TargetType="Label">
25+
<Setter Property="HorizontalTextAlignment" Value="Start" />
26+
<Setter Property="VerticalTextAlignment" Value="Center" />
27+
</Style>
28+
<Style x:Key="ConfirmButton" TargetType="Button">
29+
<Setter Property="VerticalOptions" Value="End" />
30+
</Style>
31+
</ResourceDictionary>
32+
</VerticalStackLayout.Resources>
3333

34-
<Label Style="{StaticResource Title}" Text="Button Popup" />
35-
<BoxView Style="{StaticResource Divider}" />
36-
<Label Style="{StaticResource Content}" Text="This is a platform specific popup with a .NET MAUI View being rendered. The behaviors of the popup will confirm to 100% this platform look and feel, but still allows you to use your .NET MAUI controls." />
37-
<Button
34+
<Label Style="{StaticResource Title}" Text="Button Popup" Loaded="Label_Loaded" />
35+
<BoxView Style="{StaticResource Divider}" />
36+
<Label Style="{StaticResource Content}" Text="This is a platform specific popup with a .NET MAUI View being rendered. The behaviors of the popup will confirm to 100% this platform look and feel, but still allows you to use your .NET MAUI controls." />
37+
<Button
3838
Clicked="Button_Clicked"
3939
Style="{StaticResource ConfirmButton}"
4040
Text="OKAY" />
41-
</VerticalStackLayout>
41+
</VerticalStackLayout>
4242
</mct:Popup>

samples/CommunityToolkit.Maui.Sample/Views/Popups/ButtonPopup.xaml.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,4 +11,12 @@ void Button_Clicked(object? sender, EventArgs e)
1111
{
1212
CloseAsync();
1313
}
14+
15+
void Label_Loaded(object sender, EventArgs e)
16+
{
17+
if (sender is Label label)
18+
{
19+
label.SetSemanticFocus();
20+
}
21+
}
1422
}

0 commit comments

Comments
 (0)