I guess, you'll need to create a custom (templated) control, something like this:
public partial class CalendarViewEx : CalendarView
{
public CalendarViewEx()
{
this.DefaultStyleKey = typeof(CalendarViewEx);
Loaded += CalendarViewEx_Loaded;
Unloaded += CalendarViewEx_Unloaded;
}
private long HeaderButtonContentChangeToken { get; set; }
private Button? HeaderButton { get; set; }
private void CalendarViewEx_Loaded(object sender, RoutedEventArgs e)
{
if (GetTemplateChild("HeaderButton") is Button headerButton)
{
HeaderButton = headerButton;
HeaderButtonContentChangeToken = HeaderButton.RegisterPropertyChangedCallback(Button.ContentProperty, OnHeaderButtonContentPropertyChanged);
}
RefreshCalenderViewDayItems();
}
private void CalendarViewEx_Unloaded(object sender, RoutedEventArgs e)
{
if (HeaderButton is not null)
{
HeaderButton.UnregisterPropertyChangedCallback(Button.ContentProperty, HeaderButtonContentChangeToken);
HeaderButton = null;
}
}
private void OnHeaderButtonContentPropertyChanged(DependencyObject sender, DependencyProperty dp)
{
RefreshCalenderViewDayItems();
}
private void RefreshCalenderViewDayItems()
{
if (HeaderButton?.Content is not string headerText)
{
return;
}
// Removes hidden unicode characters.
var cleanedHeaderText = new string([.. headerText.Where(c => !char.IsControl(c) && CharUnicodeInfo.GetUnicodeCategory(c) != UnicodeCategory.Format)]);
// You might need to modify this according to the language.
if (!DateTime.TryParseExact(cleanedHeaderText, "MMMM yyyy", CultureInfo.InvariantCulture, DateTimeStyles.None, out var headerDate))
{
System.Diagnostics.Debug.WriteLine($"Failed to parse header text: {headerText}");
return;
}
foreach (CalendarViewDayItem item in this.FindDescendants().OfType<CalendarViewDayItem>())
{
item.Visibility = item.Date.Month != headerDate.Month ? Visibility.Collapsed : Visibility.Visible;
}
}
}
<Style TargetType="local:CalendarViewEx" BasedOn="{StaticResource DefaultCalendarViewStyle}" />