public override void OnApplyTemplate()
        {
            base.OnApplyTemplate();
            MyGroupsListBox = GetTemplateChild("MyGroupsListBox") as ListBox;
            ProgressIndicator = GetTemplateChild("ProgressIndicator") as ProgressIndicator;
            SearchResultsTextBlock = GetTemplateChild("SearchResultsTextBlock") as TextBlock;
            Title = GetTemplateChild("Title") as TextBlock;

            if (MyGroupsListBox != null)
                MyGroupsListBox.DataContext = this;
            ArcGISOnlineEnvironment.ArcGISOnline.User.SignedInOut += new EventHandler(ArcGISOnline_SignedInOut);
            if (pendingActivation)
                Activate(TypeOfGroups);
        }
        public override void OnApplyTemplate()
        {
            if (MapDetailsControl != null)
                MapDetailsControl.MapSelectedForOpening -= RaiseMapSelectedForOpening;
            if (SearchTextBox != null)
                SearchTextBox.KeyDown -= SearchTextBox_KeyDown;
            if (SearchButton != null)
                SearchButton.Click -= SearchButton_Click;
            if (MapResultsListBox != null)
                MapResultsListBox.SelectionChanged -= ResultListBox_SelectionChanged;
            if (SearchMapsButton != null)
                SearchMapsButton.Click -= SearchMapsButton_Click;
            if (SearchGroupsButton != null)
                SearchGroupsButton.Click -= SearchGroupsButton_Click;
            if (MostRelevant != null)
                MostRelevant.Click -= SortByMenuToggleButton_Click;
            if (MostPopular != null)
                MostPopular.Click -= SortByMenuToggleButton_Click;
            if (HighestRated != null)
                HighestRated.Click -= SortByMenuToggleButton_Click;
            if (MostRecentlyAdded != null)
                MostRecentlyAdded.Click -= SortByMenuToggleButton_Click;
            if (TitleAtoZ != null)
                TitleAtoZ.Click -= SortByMenuToggleButton_Click;
            if (TitleZtoA != null)
                TitleZtoA.Click -= SortByMenuToggleButton_Click;
            if (MostComments != null)
                MostComments.Click -= SortByMenuToggleButton_Click;
            if (SortByToggleButton != null)
                SortByToggleButton.Click -= SortByToggleButton_Click;
            if (SortByMenuPopup != null)
                SortByMenuPopup.Closed -= SortByMenuPopup_Closed;
            if (SortByToggleButtonStackPanel != null)
                SortByToggleButtonStackPanel.LostFocus -= SortByToggleButtonStackPanel_LostFocus;

            base.OnApplyTemplate();

            MapDetailsControl = GetTemplateChild("MapDetailsControl") as MapDetailsControl;
            SearchTextBox = GetTemplateChild("SearchTextBox") as TextBox;
            SearchMapsButton = GetTemplateChild("SearchMapsButton") as RadioButton;
            SearchButton = GetTemplateChild("SearchButton") as Button;
            ProgressIndicator = GetTemplateChild("ProgressIndicator") as ProgressIndicator;
            DataPager = GetTemplateChild("DataPager") as DataPager;
            GroupResultsListBox = GetTemplateChild("GroupResultsListBox") as ListBox;
            SearchResultsTextBlock = GetTemplateChild("SearchResultsTextBlock") as TextBlock;
            MapResultsListBox = GetTemplateChild("MapResultsListBox") as ListBox;
            SearchResultsHeaderCanvas = GetTemplateChild("SearchResultsHeaderCanvas") as Canvas;
            SortByToggleButton = GetTemplateChild("SortByToggleButton") as ToggleButton;
            SortByMenuPopup = GetTemplateChild("SortByMenuPopup") as Popup;
            SortByMenuBorder = GetTemplateChild("SortByMenuBorder") as Border;
            SortByToggleButtonStackPanel = GetTemplateChild("SortByToggleButtonStackPanel") as StackPanel;
            SearchGroupsButton = GetTemplateChild("SearchGroupsButton") as RadioButton;
            MostRelevant = GetTemplateChild("MostRelevant") as ToggleButton;
            MostPopular = GetTemplateChild("MostPopular") as ToggleButton;
            HighestRated = GetTemplateChild("HighestRated") as ToggleButton;
            MostRecentlyAdded = GetTemplateChild("MostRecentlyAdded") as ToggleButton;
            TitleAtoZ = GetTemplateChild("TitleAtoZ") as ToggleButton;
            TitleZtoA = GetTemplateChild("TitleZtoA") as ToggleButton;
            MostComments = GetTemplateChild("MostComments") as ToggleButton;

            if (MapDetailsControl != null)
                MapDetailsControl.MapSelectedForOpening += RaiseMapSelectedForOpening;
            if (SearchTextBox != null)
            {
                SearchTextBox.KeyDown += SearchTextBox_KeyDown;
                SearchTextBox.Focus();
            }
            if (SearchButton != null)
                SearchButton.Click += SearchButton_Click;
            if (MapResultsListBox != null)
            {
                MapResultsListBox.SelectionChanged += ResultListBox_SelectionChanged;
                MapResultsListBox.DataContext = this;
            }
            if (GroupResultsListBox != null)
                GroupResultsListBox.DataContext = this;
            if (SearchMapsButton != null)
                SearchMapsButton.Click += SearchMapsButton_Click;
            if (SearchGroupsButton != null)
                SearchGroupsButton.Click += SearchGroupsButton_Click;
            if (MostRelevant != null)
                MostRelevant.Click += SortByMenuToggleButton_Click;
            if (MostPopular != null)
                MostPopular.Click += SortByMenuToggleButton_Click;
            if (HighestRated != null)
                HighestRated.Click += SortByMenuToggleButton_Click;
            if (MostRecentlyAdded != null)
                MostRecentlyAdded.Click += SortByMenuToggleButton_Click;
            if (TitleAtoZ != null)
                TitleAtoZ.Click += SortByMenuToggleButton_Click;
            if (TitleZtoA != null)
                TitleZtoA.Click += SortByMenuToggleButton_Click;
            if (MostComments != null)
                MostComments.Click += SortByMenuToggleButton_Click;
            if (SortByToggleButton != null)
                SortByToggleButton.Click += SortByToggleButton_Click;
            if (SortByMenuPopup != null)
                SortByMenuPopup.Closed += SortByMenuPopup_Closed;
            if (SortByToggleButtonStackPanel != null)
                SortByToggleButtonStackPanel.LostFocus += SortByToggleButtonStackPanel_LostFocus;
            if (pendingSearch != null && SearchTextBox != null && SearchMapsButton != null)
            {
                DoSearch(pendingSearch.Term, pendingSearch.Type);
                pendingSearch = null;
            }
        }
        public override void OnApplyTemplate()
        {
            if (MapDetailsControl != null)
            {
                MapDetailsControl.MapSelectedForOpening -= RaiseMapSelectedForOpening;
            }
            if (SearchTextBox != null)
            {
                SearchTextBox.KeyDown -= SearchTextBox_KeyDown;
            }
            if (SearchButton != null)
            {
                SearchButton.Click -= SearchButton_Click;
            }
            if (MapResultsListBox != null)
            {
                MapResultsListBox.SelectionChanged -= ResultListBox_SelectionChanged;
            }
            if (SearchMapsButton != null)
            {
                SearchMapsButton.Click -= SearchMapsButton_Click;
            }
            if (SearchGroupsButton != null)
            {
                SearchGroupsButton.Click -= SearchGroupsButton_Click;
            }
            if (MostRelevant != null)
            {
                MostRelevant.Click -= SortByMenuToggleButton_Click;
            }
            if (MostPopular != null)
            {
                MostPopular.Click -= SortByMenuToggleButton_Click;
            }
            if (HighestRated != null)
            {
                HighestRated.Click -= SortByMenuToggleButton_Click;
            }
            if (MostRecentlyAdded != null)
            {
                MostRecentlyAdded.Click -= SortByMenuToggleButton_Click;
            }
            if (TitleAtoZ != null)
            {
                TitleAtoZ.Click -= SortByMenuToggleButton_Click;
            }
            if (TitleZtoA != null)
            {
                TitleZtoA.Click -= SortByMenuToggleButton_Click;
            }
            if (MostComments != null)
            {
                MostComments.Click -= SortByMenuToggleButton_Click;
            }
            if (SortByToggleButton != null)
            {
                SortByToggleButton.Click -= SortByToggleButton_Click;
            }
            if (SortByMenuPopup != null)
            {
                SortByMenuPopup.Closed -= SortByMenuPopup_Closed;
            }
            if (SortByToggleButtonStackPanel != null)
            {
                SortByToggleButtonStackPanel.LostFocus -= SortByToggleButtonStackPanel_LostFocus;
            }

            base.OnApplyTemplate();

            MapDetailsControl            = GetTemplateChild("MapDetailsControl") as MapDetailsControl;
            SearchTextBox                = GetTemplateChild("SearchTextBox") as TextBox;
            SearchMapsButton             = GetTemplateChild("SearchMapsButton") as RadioButton;
            SearchButton                 = GetTemplateChild("SearchButton") as Button;
            ProgressIndicator            = GetTemplateChild("ProgressIndicator") as ProgressIndicator;
            DataPager                    = GetTemplateChild("DataPager") as DataPager;
            GroupResultsListBox          = GetTemplateChild("GroupResultsListBox") as ListBox;
            SearchResultsTextBlock       = GetTemplateChild("SearchResultsTextBlock") as TextBlock;
            MapResultsListBox            = GetTemplateChild("MapResultsListBox") as ListBox;
            SearchResultsHeaderCanvas    = GetTemplateChild("SearchResultsHeaderCanvas") as Canvas;
            SortByToggleButton           = GetTemplateChild("SortByToggleButton") as ToggleButton;
            SortByMenuPopup              = GetTemplateChild("SortByMenuPopup") as Popup;
            SortByMenuBorder             = GetTemplateChild("SortByMenuBorder") as Border;
            SortByToggleButtonStackPanel = GetTemplateChild("SortByToggleButtonStackPanel") as StackPanel;
            SearchGroupsButton           = GetTemplateChild("SearchGroupsButton") as RadioButton;
            MostRelevant                 = GetTemplateChild("MostRelevant") as ToggleButton;
            MostPopular                  = GetTemplateChild("MostPopular") as ToggleButton;
            HighestRated                 = GetTemplateChild("HighestRated") as ToggleButton;
            MostRecentlyAdded            = GetTemplateChild("MostRecentlyAdded") as ToggleButton;
            TitleAtoZ                    = GetTemplateChild("TitleAtoZ") as ToggleButton;
            TitleZtoA                    = GetTemplateChild("TitleZtoA") as ToggleButton;
            MostComments                 = GetTemplateChild("MostComments") as ToggleButton;

            if (MapDetailsControl != null)
            {
                MapDetailsControl.MapSelectedForOpening += RaiseMapSelectedForOpening;
            }
            if (SearchTextBox != null)
            {
                SearchTextBox.KeyDown += SearchTextBox_KeyDown;
                SearchTextBox.Focus();
            }
            if (SearchButton != null)
            {
                SearchButton.Click += SearchButton_Click;
            }
            if (MapResultsListBox != null)
            {
                MapResultsListBox.SelectionChanged += ResultListBox_SelectionChanged;
                MapResultsListBox.DataContext       = this;
            }
            if (GroupResultsListBox != null)
            {
                GroupResultsListBox.DataContext = this;
            }
            if (SearchMapsButton != null)
            {
                SearchMapsButton.Click += SearchMapsButton_Click;
            }
            if (SearchGroupsButton != null)
            {
                SearchGroupsButton.Click += SearchGroupsButton_Click;
            }
            if (MostRelevant != null)
            {
                MostRelevant.Click += SortByMenuToggleButton_Click;
            }
            if (MostPopular != null)
            {
                MostPopular.Click += SortByMenuToggleButton_Click;
            }
            if (HighestRated != null)
            {
                HighestRated.Click += SortByMenuToggleButton_Click;
            }
            if (MostRecentlyAdded != null)
            {
                MostRecentlyAdded.Click += SortByMenuToggleButton_Click;
            }
            if (TitleAtoZ != null)
            {
                TitleAtoZ.Click += SortByMenuToggleButton_Click;
            }
            if (TitleZtoA != null)
            {
                TitleZtoA.Click += SortByMenuToggleButton_Click;
            }
            if (MostComments != null)
            {
                MostComments.Click += SortByMenuToggleButton_Click;
            }
            if (SortByToggleButton != null)
            {
                SortByToggleButton.Click += SortByToggleButton_Click;
            }
            if (SortByMenuPopup != null)
            {
                SortByMenuPopup.Closed += SortByMenuPopup_Closed;
            }
            if (SortByToggleButtonStackPanel != null)
            {
                SortByToggleButtonStackPanel.LostFocus += SortByToggleButtonStackPanel_LostFocus;
            }
            if (pendingSearch != null && SearchTextBox != null && SearchMapsButton != null)
            {
                DoSearch(pendingSearch.Term, pendingSearch.Type);
                pendingSearch = null;
            }
        }
 public override void OnApplyTemplate()
 {
     if (FieldListBox != null)
         FieldListBox.SelectionChanged -= FieldListBox_SelectionChanged;
     if (WhereClauseTextBox != null)
         WhereClauseTextBox.KeyDown -= WhereClauseTextBox_KeyDown;
     if (OKButton != null)
         OKButton.Click -= OKButton_Click;
     if (ExpressionDatePicker != null)
         ExpressionDatePicker.SelectedDateChanged -= DatePicker_SelectedDateChanged;
     base.OnApplyTemplate();
     FieldListBox = GetTemplateChild("FieldListBox") as ListBox;
     WhereClauseTextBox = GetTemplateChild("WhereClauseTextBox") as TextBox;
     OKButton = GetTemplateChild("OKButton") as Button;
     ExpressionDatePicker = GetTemplateChild("ExpressionDatePicker") as DatePicker;
     PreviewDataGrid = GetTemplateChild("PreviewDataGrid") as DataGrid;
     DataPreviewProgressIndicator = GetTemplateChild("DataPreviewProgressIndicator") as ProgressIndicator;
     FailedPreviewTextBlock = GetTemplateChild("FailedPreviewTextBlock") as TextBlock;
     ExpressionDatePickerButton = GetTemplateChild("ExpressionDatePickerButton") as Button;
     if (FieldListBox != null)
         FieldListBox.SelectionChanged += FieldListBox_SelectionChanged;
     if (WhereClauseTextBox != null)
         WhereClauseTextBox.KeyDown += WhereClauseTextBox_KeyDown;
     if (OKButton != null)
         OKButton.Click += OKButton_Click;
     if (ExpressionDatePicker != null)
         ExpressionDatePicker.SelectedDateChanged += DatePicker_SelectedDateChanged;
     setQueryProps();
 }