This screen consists of a form that will store the days of the week and their respective times when a sports court is open to the public.
The HoraInicio (initial time) and HoraFim (end time) properties are coming with the value 00: 00: 00.


XAML
xaml
<StackLayout BindableLayout.ItemsSource="{Binding Horarios}">
<BindableLayout.ItemTemplate>
<DataTemplate>
<StackLayout Orientation="Horizontal" HeightRequest="40">
<Switch x:Name="AbertoSwitch"
IsToggled="{Binding Aberto}"
Toggled="AlteracaoDoEstadoDoSwitch"
VerticalOptions="Center"/>
<Label Text="{Binding DiaDaSemanaText}"
HorizontalOptions="FillAndExpand"
VerticalOptions="Center"/>
<TimePicker BindingContext="{x:Reference AbertoSwitch}"
IsVisible="{Binding IsToggled}"
VerticalOptions="Center"
Format="HH:mm"
Time="{Binding HoraInicio}"/>
<TimePicker BindingContext="{x:Reference AbertoSwitch}"
IsVisible="{Binding IsToggled}"
VerticalOptions="Center"
Format="HH:mm"
Time="{Binding HoraFim}"/>
</StackLayout>
</DataTemplate>
</BindableLayout.ItemTemplate>
``</StackLayout>
ViewModel
public TimeSpan HoraInicio { get => horaInicio; set => SetProperty(ref horaInicio, value); }
public TimeSpan HoraFim { get => horaFim; set => SetProperty(ref horaFim, value); }
public void AtribuirHorarioParaCadaDiaDisponivel()
{
try
{
for (int i = 0; i <= 6; i++)
{
if (this.Horarios[i].Aberto == true)
{
this.Horarios[i].HoraInicio = this.HoraInicio.ToString();
this.Horarios[i].HoraFim = this.HoraFim.ToString();
}
}
}
catch (Exception)
{
throw new Exception("Horário(s) incorreto(s)");
}
}
