public override void OnApplyTemplate()
{
if (expandButton != null) expandButton.Click -= OnExpandClick;
expandButton = GetTemplateChild("PART_ExpandButton") as ToggleButton;
if (expandButton != null) expandButton.Click += OnExpandClick;
if (dropDownButton != null) dropDownButton.Click -= OnDropDownClick;
dropDownButton = GetTemplateChild("PART_DropDownButton") as ToggleButton;
if (dropDownButton != null) dropDownButton.Click += OnDropDownClick;
layoutRoot = GetTemplateChild("PART_LayoutRoot") as Panel;
if (popup != null)
{
popup.Opened -= OnDropDownOpened;
popup.Closed -= OnDropDownClosed;
popup.PreviewMouseLeftButtonUp -= OnPopupPreviewMouseUp;
popup.PreviewMouseLeftButtonDown -= OnPopupPreviewMouseDown;
}
popup = GetTemplateChild("PART_Popup") as Popup;
if (popup != null)
{
popup.Opened += OnDropDownOpened;
popup.Closed += OnDropDownClosed;
popup.PreviewMouseLeftButtonUp += OnPopupPreviewMouseUp;
popup.PreviewMouseLeftButtonDown += OnPopupPreviewMouseDown;
KeyboardNavigation.SetControlTabNavigation(popup, KeyboardNavigationMode.Cycle);
KeyboardNavigation.SetDirectionalNavigation(popup, KeyboardNavigationMode.Cycle);
KeyboardNavigation.SetTabNavigation(popup, KeyboardNavigationMode.Cycle);
}
if (resizeVerticalThumb != null)
{
resizeVerticalThumb.DragDelta -= OnResizeVerticalDelta;
}
resizeVerticalThumb = GetTemplateChild("PART_ResizeVerticalThumb") as Thumb;
if (resizeVerticalThumb != null)
{
resizeVerticalThumb.DragDelta += OnResizeVerticalDelta;
}
if (resizeBothThumb != null)
{
resizeBothThumb.DragDelta -= OnResizeBothDelta;
}
resizeBothThumb = GetTemplateChild("PART_ResizeBothThumb") as Thumb;
if (resizeBothThumb != null)
{
resizeBothThumb.DragDelta += OnResizeBothDelta;
}
menuPanel = GetTemplateChild("PART_MenuPanel") as Panel;
if (groupsMenuButton != null) groupsMenuButton.Items.Clear();
groupsMenuButton = GetTemplateChild("PART_FilterDropDownButton") as DropDownButton;
if (groupsMenuButton != null)
{
for (int i = 0; i < Filters.Count; i++)
{
MenuItem item = new MenuItem();
item.Header = Filters[i].Title;
item.Tag = Filters[i];
item.IsDefinitive = false;
if (Filters[i] == SelectedFilter) item.IsChecked = true;
item.Click += OnFilterMenuItemClick;
groupsMenuButton.Items.Add(item);
}
}
galleryPanel = GetTemplateChild("PART_GalleryPanel") as GalleryPanel;
if (galleryPanel != null)
{
galleryPanel.MinItemsInRow = MaxItemsInRow;
galleryPanel.MaxItemsInRow = MaxItemsInRow;
}
snappedImage = GetTemplateChild("PART_FakeImage") as Image;
controlPresenter = GetTemplateChild("PART_ContentPresenter") as ContentControl;
popupControlPresenter = GetTemplateChild("PART_PopupContentPresenter") as ContentControl;
scrollViewer = GetTemplateChild("PART_ScrollViewer") as ScrollViewer;
}