1

I'm using WinUI3/Windows App SDK 1.3 - XAML/C# My problem is that most UIs today have a de facto "Today" button on their calendar controls. In WASDK/WinUI, the control is called "CalendarView" and works great. Unfortunately, it does not have a "Today" button that when clicked, should scroll the calendar to today's date.

I already have a simple button atop the CalendarView, but looking into the documentations from Microsoft, there's no functionality for what I'm trying to achieve.

Here's the default CalendarView control: Exhibit A

Now here's the calendar with my button: Exhibit B

What I would like to do is when I click on the "Today" button, the calendar will automatically update itself to scroll into today's date. Example, the calendar is currently displaying the month of December 2050, when I click on today button, the calendar should auto-scroll back to the current month, day and year.

Any guidance or tips would be greatly appreciated. Thanks in advance!

2 Answers 2

2

In the C# code, create a function to retrieve the current date and scroll the calendar view to today's date.

private void TodayButton_Click(object sender, RoutedEventArgs e)
{
  // Get the current date
  DateTime today = DateTime.Today;

  // Scroll the CalendarView to today's date
  calendarView.ChangeView(today, null, null);
}

In the XAML code, link the "Today" button to this function.

<Button x:Name="TodayButton" Content="Today" Click="TodayButton_Click" />
Sign up to request clarification or add additional context in comments.

1 Comment

Hi, the ChangeView method is nowhere to be found in learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/…, however, I found this method learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/… which does the job. I appreciate your help.
0

https://learn.microsoft.com/en-us/windows/windows-app-sdk/api/winrt/microsoft.ui.xaml.controls.calendarview.setdisplaydate?view=windows-app-sdk-1.2#microsoft-ui-xaml-controls-calendarview-setdisplaydate(windows-foundation-datetime)

CalendarView.SetDisplayDate(DateTimeOffset.Now);

1 Comment

Your answer could be improved by providing an example of the solution and how it solves the problem.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.