/// <summary> /// Clear our layout-specific data, and detach our current itemscontrol from monthcalendar /// </summary> private void DetachFromVisualTree() { if (_mccContainer != null) { _mccContainer.LayoutUpdated -= new EventHandler(OnContainerLayoutUpdated); _mccContainer.SelectionChanged -= new SelectionChangedEventHandler(OnContainerSelectionChanged); _mccContainer = null; } }
/// <summary> /// Walk to visual tree to find the MonthCalendarContainer. Set the GroupFactory and GroupPanel. /// Register the selection change event if it is a Selector. /// </summary> 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(); }