Extract GetFirstDateToRender in the calendar model so it can be executed even before the calendar ViewModels are loaded

This commit is contained in:
ni4ka7a 2018-11-09 15:04:25 +02:00
Родитель 4cac495ce2
Коммит f4fb8451cb
6 изменённых файлов: 59 добавлений и 33 удалений

Просмотреть файл

@ -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)