private void AttachToVisualTree()
{
DetachFromVisualTree();
// Walk the visual tree to find the MonthCalendarContainer.
_mccContainer = GetTemplateChild(c_VisibleDaysHostTemplateName) as MonthCalendarContainer;
if (_mccContainer != null)
{
_mccContainer.ItemsSource = VisibleDays;
RefreshDayTemplate();
_mccContainer.LayoutUpdated += new EventHandler(OnContainerLayoutUpdated);
_mccContainer.SelectionChanged += new SelectionChangedEventHandler(OnContainerSelectionChanged);
//If MonthCalendar's visualtree is restyled, set this flag to true to update the SelectedDates on new UI
SetFlag(Flags.IsVisualTreeUpdated, true);
}
RefreshPreviousButtonStyle();
RefreshNextButtonStyle();
}