Microsoft.Samples.KMoore.WPFSamples.DateControls.MonthCalendar.RestoreSelection C# (CSharp) Method

RestoreSelection() private method

Restore the selection UI after switching month
private RestoreSelection ( int scrollChange ) : void
scrollChange int
return void
        private void RestoreSelection(int scrollChange)
        {
            if (SelectionChange.IsActive || SelectedDates.Count == 0)
            {
                return;
            }

            SelectionChange.Begin();
            bool succeeded = false;
            try
            {
                //Restore the selected dates that are within Max/MinDate, First/LastVisibleDate
                //And unselect the dates that exceeds the range
                foreach (DateTime dt in SelectedDates)
                {
                    if (MonthCalendarHelper.IsWithinRange(dt, FirstVisibleDate, LastVisibleDate)
                        && MonthCalendarHelper.IsWithinRange(dt, MinDate, MaxDate))
                    {
                        SelectionChange.RestoreSelect(dt);
                    }
                    else
                    {
                        SelectionChange.Unselect(dt);
                    }
                }

                SelectionChange.End(true, true);
                succeeded = true;
            }
            finally
            {
                if (!succeeded)
                {
                    SelectionChange.Cancel();
                }
            }
        }