rename LottoPickerException to LotteryException

add SemanticScreenReader Announcement on button clicked.
It reads the text from the NumbersLabel
This commit is contained in:
onyx-and-iris 2024-09-27 02:01:24 +01:00
parent 900fd940cf
commit e1ab2087a2
4 changed files with 12 additions and 11 deletions

View File

@ -5,10 +5,10 @@
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Lottery"
Shell.FlyoutBehavior="Disabled"
Title="">
Title="Lottery Number Generator">
<ShellContent
Title="Lottery Number Picker"
Title="Lottery Number Generator"
ContentTemplate="{DataTemplate local:MainPage}"
Route="MainPage" />

View File

@ -1,9 +1,9 @@
namespace Lottery
{
/// <summary>
/// Base Exception class for the LottoPicker app
/// Base Exception class for the Lottery app
/// </summary>
internal class LottoPickerException(string message) : Exception(message)
internal class LotteryException(string message) : Exception(message)
{
}
}

View File

@ -7,7 +7,7 @@
<VerticalStackLayout
Padding="30,0"
Spacing="25">
<Picker x:Name="LottoPicker" Title="Kind of Lottery" SelectedIndexChanged="LottoPicker_SelectedIndexChanged" />
<Picker x:Name="LotteryPicker" Title="Kind of Lottery" SelectedIndexChanged="LotteryPicker_SelectedIndexChanged" />
<Label x:Name="NumbersLabel" Text="Click Spin button to generate" HorizontalOptions="Center" FontSize="Medium" />

View File

@ -16,10 +16,10 @@
InitializeComponent();
List<string> lottos = ["UK Lotto", "EuroMillions", "Set For Life", "Thunderball"];
LottoPicker.ItemsSource = lottos;
LottoPicker.SelectedIndex = (int)DefaultLottery;
LotteryPicker.ItemsSource = lottos;
LotteryPicker.SelectedIndex = (int)DefaultLottery;
Lottery = Lotteries[LottoPicker.SelectedIndex];
Lottery = Lotteries[LotteryPicker.SelectedIndex];
}
private void SpinButton_Clicked(object sender, EventArgs e)
@ -43,14 +43,15 @@
}
break;
default:
throw new LottoPickerException($"no NumbersLabel output defined for {numbers.Kind}");
throw new LotteryException($"no NumbersLabel output defined for {numbers.Kind}");
};
NumbersLabel.Text = string.Join("\t", output);
SemanticScreenReader.Announce(NumbersLabel.Text);
}
private void LottoPicker_SelectedIndexChanged(object sender, EventArgs e)
private void LotteryPicker_SelectedIndexChanged(object sender, EventArgs e)
{
Lottery = Lotteries[LottoPicker.SelectedIndex];
Lottery = Lotteries[LotteryPicker.SelectedIndex];
}
}
}