A peculiar behavior we have found with the RadCalendar control:
We have a custom DayButtonStyleSelector set to an instance of a RadCalendar. This StyleSelector sets the Visibility of days that do not belong to the month displayed as Collapsed, instead of being grayed out as they normally would be.
Furthermore, we dynamically change the number of columns displayed dependent on the width available to the RadCalendar.
The StyleSelector works as intended when loading the Calendar and when increasing the column count, but when we reduce the column count by reducing the space available for the RadCalendar control, the last column seems to ignore the StyleSelector and displays the days of the following month in grey.
However, using Snoop we found out that the Style is applied - and consequently overridden by a locally set Visibility.
This only happens for the last column, and only when reducing the number of columns. Please see the attached screenshots (1.jpg shows the Calendar after loading, 2.jpg shows the calendar after expanding enough to display a third column, 3.jpg shows the calendar after reducing it back to 2 columns).
A code sample to illustrate this problem:
<Window x:Class="MainWindow" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation" Title="MainWindow" Height="200" Width="400"> <telerik:RadCalendar VerticalAlignment="Stretch" HorizontalAlignment="Stretch" Name="cal" /></Window>
And the code behind (please excuse the VB.Net):
Imports Telerik.Windows.Controls.CalendarClass MainWindow Private Const MinCalendarWidth = 150 Public Sub New() ' This call is required by the designer. InitializeComponent() ' Add any initialization after the InitializeComponent() call. cal.DayButtonStyle = Nothing cal.DayButtonStyleSelector = New CDayStyleSelector() End Sub Protected Overrides Sub OnRenderSizeChanged(sizeInfo As SizeChangedInfo) MyBase.OnRenderSizeChanged(sizeInfo) Dim CalendarColumns = Math.Max(1, CInt(Math.Floor(sizeInfo.NewSize.Width / MinCalendarWidth))) If cal.Columns <> CalendarColumns Then cal.Columns = CalendarColumns End If End Sub Private Class CDayStyleSelector Inherits StyleSelector Private _HideButtonStyle As New Style Public Sub New() _HideButtonStyle.Setters.Add(New Setter(VisibilityProperty, Visibility.Collapsed)) End Sub Public Overrides Function SelectStyle(item As Object, container As DependencyObject) As Style Dim Content = TryCast(item, CalendarButtonContent) If Content IsNot Nothing AndAlso Content.ButtonType = CalendarButtonType.Date Then If Not Content.IsFromCurrentView OrElse Content.IsInAnotherView Then Return _HideButtonStyle 'Hide all Buttons of other months End If End If Return MyBase.SelectStyle(item, container) End Function End ClassEnd Class
You can observe the problem described by changing the width of the window.