English 中文(简体)
How do I make CalendarView automatically scroll to today?
原标题:

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!

问题回答

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" />




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签