I am new to .NET MAUI.
I have a calendar:
And this is my XAML:
<VerticalStackLayout HorizontalOptions="Center">
<CollectionView
ItemsSource="{Binding CalendarModel}"
SelectionMode="None">
<CollectionView.ItemsLayout>
<GridItemsLayout Orientation="Horizontal" />
</CollectionView.ItemsLayout>
<CollectionView.ItemTemplate >
<DataTemplate x:DataType="model:CalendarModel">
<Border Margin="1,1,1,1" >
<Grid>
<Frame BackgroundColor="#6CA0DC" CornerRadius="0" WidthRequest="80">
<Frame.Triggers>
<DataTrigger TargetType="Frame" Binding="{Binding IsCurrentDay}" Value="true">
<Setter Property="BackgroundColor" Value="#008080" />
</DataTrigger>
</Frame.Triggers>
<Frame.GestureRecognizers>
<TapGestureRecognizer
Command="{Binding Source={RelativeSource AncestorType={x:Type viewmodel:CalendarViewModel}}, Path=HighlightSelectedDayCommand}"
CommandParameter="{Binding .}"/>
</Frame.GestureRecognizers>
<Grid>
<VerticalStackLayout>
<Label Text="{Binding DayName}" TextTransform="Default" TextColor="White" FontSize="Header"></Label>
<Label Text="{Binding DayNumber}" TextColor="White" FontSize="Subtitle" FontAttributes="Bold"></Label>
</VerticalStackLayout>
</Grid>
</Frame>
</Grid>
</Border>
</DataTemplate>
</CollectionView.ItemTemplate>
</CollectionView>
</VerticalStackLayout>
I want my current date to be in focused when the new month is loaded. or scroll to the current day display the day 1 of the previous and next month. something like this:
This is my ViewModel
[RelayCommand]
async Task PopulateNextMonth()
{
currentCalendar[0] = currentCalendar[0] == 12 ? 1 : currentCalendar[0] + 1;
currentCalendar[1] = currentCalendar[0] == 1 ? currentCalendar[1] + 1 : currentCalendar[1];
await PopulateCalendar();
}
[RelayCommand]
async Task PopulatePreviousMonth()
{
currentCalendar[0] = currentCalendar[0] == 1 ? 12 : currentCalendar[0] - 1;
currentCalendar[1] = currentCalendar[0] == 12 ? currentCalendar[1] - 1 : currentCalendar[1];
await PopulateCalendar();
}