我正在使用Telerik RadCalendar,当我通过SelectDates以编程方式选择单元格时,CustomCellDecorator不会检测到它。
我正在OnElementPropertyChanged方法的customRenderer类中编写以下代码 代码:-
CellDecorator decorator = new FlagCellDecorator(Control);
decorator.Color = 0;
decorator.Stroked = true;
decorator.Scale = 1.5f;
Control.CellDecorator = decorator;
Control.CellDecorationsLayer.StrokeWidth = 1f;
Calendar calendar = Calendar.Instance;
Control.SelectedDatesChanged += Control_SelectedDatesChanged;
if (Element.AppointmentsSource != null && !IsSelected)
{
List<Long> dates = new List<Long>();
foreach (var item in Element.AppointmentsSource)
{
calendar.Set(item.StartDate.Year, item.StartDate.Month, item.StartDate.Day);
dates.Add(new Long(calendar.TimeInMillis));
calendar.Set(item.EndDate.Year, item.EndDate.Month, item.EndDate.Day);
dates.Add(new Long(calendar.TimeInMillis));
}
Control.SelectedDates = dates;
}
自定义单元格装饰器类:-
class FlagCellDecorator : CellDecorator
{
private float offsetVertical;
public FlagCellDecorator(RadCalendarView owner) : base(owner)
{
this.offsetVertical = owner.GridLinesLayer.Width / 2;
}
protected override void RenderDecorationForCell(Canvas canvas,
CalendarCell cell)
{
int offsetHorizontal =
(cell.Width - (int)(cell.Width * this.Scale)) / 2;
canvas.DrawRoundRect(cell.VirtualLeft(),
cell.VirtualTop(),
cell.VirtualRight() - offsetHorizontal,
cell.VirtualBottom(), 20, 20, this.Paint);
canvas.DrawText(cell.Text,
cell.TextPositionX() + cell.VirtualOffsetX,
cell.TextPositionY() + cell.VirtualOffsetY,
cell.TextPaint);
}
}