Extract GetFirstDateToRender in the calendar model so it can be executed even before the calendar ViewModels are loaded
This commit is contained in:
Родитель
4cac495ce2
Коммит
f4fb8451cb
|
@ -25,7 +25,7 @@ namespace Telerik.UI.Xaml.Controls.Input.Calendar
|
|||
|
||||
internal override DateTime GetFirstDateToRender(DateTime date)
|
||||
{
|
||||
return CalendarMathHelper.GetFirstDateOfCentury(date);
|
||||
return this.Calendar.GetFirstDateToRenderForDisplayMode(date, CalendarDisplayMode.CenturyView);
|
||||
}
|
||||
|
||||
internal override DateTime GetNextDateToRender(DateTime date)
|
||||
|
|
|
@ -25,7 +25,7 @@ namespace Telerik.UI.Xaml.Controls.Input.Calendar
|
|||
|
||||
internal override DateTime GetFirstDateToRender(DateTime date)
|
||||
{
|
||||
return CalendarMathHelper.GetFirstDateOfDecade(date);
|
||||
return this.Calendar.GetFirstDateToRenderForDisplayMode(date, CalendarDisplayMode.DecadeView);
|
||||
}
|
||||
|
||||
internal override DateTime GetNextDateToRender(DateTime date)
|
||||
|
|
|
@ -418,6 +418,59 @@ namespace Telerik.UI.Xaml.Controls.Input.Calendar
|
|||
return this.View.MeasureContent(owner, content);
|
||||
}
|
||||
|
||||
internal DateTime GetFirstDateToRenderForDisplayMode(DateTime date, CalendarDisplayMode displayMode)
|
||||
{
|
||||
DateTime firstDateToRender = date;
|
||||
|
||||
if (displayMode == CalendarDisplayMode.MultiDayView)
|
||||
{
|
||||
DayOfWeek firstDayOfWeek = this.GetFirstDayOfWeek();
|
||||
DateTime firstDateOfCurrentWeek = CalendarMathHelper.GetFirstDayOfCurrentWeek(date, firstDayOfWeek);
|
||||
|
||||
if (!(firstDateOfCurrentWeek.Date <= date.Date && firstDateOfCurrentWeek.AddDays(7).Date >= date.Date))
|
||||
{
|
||||
firstDateToRender = firstDateOfCurrentWeek;
|
||||
}
|
||||
|
||||
if (!this.multiDayViewSettings.WeekendsVisible)
|
||||
{
|
||||
firstDateToRender = CalendarMathHelper.AddBusinessDays(date, -this.multiDayViewSettings.VisibleDays);
|
||||
}
|
||||
else
|
||||
{
|
||||
firstDateToRender = date.AddDays(-this.multiDayViewSettings.VisibleDays);
|
||||
}
|
||||
}
|
||||
else if (displayMode == CalendarDisplayMode.MonthView)
|
||||
{
|
||||
DayOfWeek firstDayOfWeekToUse = this.GetFirstDayOfWeek();
|
||||
|
||||
DateTime monthStartDate = CalendarMathHelper.GetFirstDateOfMonth(date);
|
||||
|
||||
int daysToSubtract = (int) monthStartDate.DayOfWeek - (int) firstDayOfWeekToUse;
|
||||
if (daysToSubtract <= 0)
|
||||
{
|
||||
daysToSubtract += 7;
|
||||
}
|
||||
|
||||
firstDateToRender = monthStartDate.Date == DateTime.MinValue.Date ? monthStartDate : monthStartDate.AddDays(-daysToSubtract);
|
||||
}
|
||||
else if (displayMode == CalendarDisplayMode.YearView)
|
||||
{
|
||||
firstDateToRender = CalendarMathHelper.GetFirstDateOfYear(date);
|
||||
}
|
||||
else if (displayMode == CalendarDisplayMode.DecadeView)
|
||||
{
|
||||
firstDateToRender = CalendarMathHelper.GetFirstDateOfDecade(date);
|
||||
}
|
||||
else if (displayMode == CalendarDisplayMode.CenturyView)
|
||||
{
|
||||
firstDateToRender = CalendarMathHelper.GetFirstDateOfCentury(date);
|
||||
}
|
||||
|
||||
return firstDateToRender;
|
||||
}
|
||||
|
||||
private void UpdateCurrentView()
|
||||
{
|
||||
switch (this.DisplayMode)
|
||||
|
|
|
@ -41,17 +41,7 @@ namespace Telerik.UI.Xaml.Controls.Input.Calendar
|
|||
|
||||
internal override DateTime GetFirstDateToRender(DateTime date)
|
||||
{
|
||||
DayOfWeek firstDayOfWeekToUse = this.Calendar.GetFirstDayOfWeek();
|
||||
|
||||
DateTime monthStartDate = CalendarMathHelper.GetFirstDateOfMonth(date);
|
||||
|
||||
int daysToSubtract = (int)monthStartDate.DayOfWeek - (int)firstDayOfWeekToUse;
|
||||
if (daysToSubtract <= 0)
|
||||
{
|
||||
daysToSubtract += 7;
|
||||
}
|
||||
|
||||
return monthStartDate.Date == DateTime.MinValue.Date ? monthStartDate : monthStartDate.AddDays(-daysToSubtract);
|
||||
return this.Calendar.GetFirstDateToRenderForDisplayMode(date, CalendarDisplayMode.MonthView);
|
||||
}
|
||||
|
||||
internal override DateTime GetNextDateToRender(DateTime dateToRender)
|
||||
|
|
|
@ -66,24 +66,7 @@ namespace Telerik.UI.Xaml.Controls.Input.Calendar
|
|||
|
||||
internal override DateTime GetFirstDateToRender(DateTime date)
|
||||
{
|
||||
DayOfWeek firstDayOfWeek = this.Calendar.GetFirstDayOfWeek();
|
||||
DateTime firstDateOfCurrentWeek = CalendarMathHelper.GetFirstDayOfCurrentWeek(date, firstDayOfWeek);
|
||||
|
||||
if (!(firstDateOfCurrentWeek.Date <= date.Date && firstDateOfCurrentWeek.AddDays(7).Date >= date.Date))
|
||||
{
|
||||
date = firstDateOfCurrentWeek;
|
||||
}
|
||||
|
||||
if (!this.Calendar.multiDayViewSettings.WeekendsVisible)
|
||||
{
|
||||
date = CalendarMathHelper.AddBusinessDays(date, -this.BufferItemsCount);
|
||||
}
|
||||
else
|
||||
{
|
||||
date = date.AddDays(-this.BufferItemsCount);
|
||||
}
|
||||
|
||||
return date;
|
||||
return this.Calendar.GetFirstDateToRenderForDisplayMode(date, CalendarDisplayMode.MultiDayView);
|
||||
}
|
||||
|
||||
internal override DateTime GetNextDateToRender(DateTime date)
|
||||
|
|
|
@ -24,8 +24,8 @@ namespace Telerik.UI.Xaml.Controls.Input.Calendar
|
|||
}
|
||||
|
||||
internal override DateTime GetFirstDateToRender(DateTime date)
|
||||
{
|
||||
return CalendarMathHelper.GetFirstDateOfYear(date);
|
||||
{
|
||||
return this.Calendar.GetFirstDateToRenderForDisplayMode(date, CalendarDisplayMode.YearView);
|
||||
}
|
||||
|
||||
internal override DateTime GetNextDateToRender(DateTime date)
|
||||
|
|
Загрузка…
Ссылка в новой задаче