This commit is contained in:
Matthew Rajala 2024-08-07 12:22:35 -04:00
Родитель d82b4a0d13
Коммит 408bf21a19
2 изменённых файлов: 16 добавлений и 28 удалений

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

@ -1649,34 +1649,6 @@ namespace Microsoft.UI.Xaml.Controls
global::System.Diagnostics.Debug.Assert(index >= 0);
global::System.Diagnostics.Debug.Assert(pHost.Panel is { });
if (pHost is CalendarViewGeneratorDecadeViewHost)
{
var rowsToMax = (MaxDate.Year - date.Year) / m_colsInYearDecadeView;
if (rowsToMax <= m_rowsInYearDecadeView / 2)
{
index -= m_rowsInYearDecadeView - rowsToMax;
int maxItemsInView = m_rowsInYearDecadeView * m_colsInYearDecadeView;
// when the last displayed date year is near the MaxDate.Year the index is offset too much
if (m_lastDisplayedDate.Year >= MaxDate.AddYears(-maxItemsInView).Year)
{
index -= m_rowsInYearDecadeView;
}
}
}
if (pHost is CalendarViewGeneratorYearViewHost && date.Year == MaxDate.Year)
{
var rowsToMax = (MaxDate.Month - date.Month) / m_colsInYearDecadeView;
if (rowsToMax <= m_rowsInYearDecadeView / 2)
{
index -= m_rowsInYearDecadeView - rowsToMax;
}
}
pHost.Panel.ScrollItemIntoView(
index,
ScrollIntoViewAlignment.Leading,

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

@ -564,6 +564,22 @@ namespace Microsoft.UI.Xaml.Controls.Primitives
renderWindow.Size = requestedRenderingWindow.Size; // The renderWindow contains only position information
startIndex = Math.Max(0, startIndex - StartIndex);
if (Rows > 0 && Cols > 0)
{
var maxItemsInView = Rows * Cols;
var totalYears = _host.Owner.MaxDate.Year - _host.Owner.MinDate.Year;
if (_host is CalendarViewGeneratorDecadeViewHost && startIndex >= totalYears - maxItemsInView)
{
startIndex = totalYears - maxItemsInView;
}
else if (_host is CalendarViewGeneratorYearViewHost && startIndex >= totalYears * 12 - maxItemsInView)
{
// TODO: find a way to get number of months in calendar so we can replace magic number
startIndex = totalYears * 12 - maxItemsInView;
}
}
// Prepare the items generator to generate some new items (will also set which items can be recycled in this measure pass).
var expectedItemsCount = LastVisibleIndex - FirstVisibleIndex;
_cache.BeginGeneration(startIndex, startIndex + expectedItemsCount);