void analysisCountryViewer_Closed(object sender, EventArgs e) { if (Popup != null && Popup.Content != null) { AnalysisCountryViewer form = Popup.Content as AnalysisCountryViewer; if (form != null) { form.Closed -= analysisCountryViewer_Closed; } } //if (Popup.Content is AnalysisCountryViewer) //{ // (Popup.Content as AnalysisCountryViewer).Closed -= analysisCountryViewer_Closed; //} Popup.Close(); Popup = null; }
void countryItem_Click(object sender, RoutedEventArgs e) { try { if (sender != null) { MenuItem item = sender as MenuItem; if (item != null && item.Tag != null) { string countryName = item.Tag.ToString(); Popup = new Popup(); FrameworkElement element = gridAnalysis.Parent as FrameworkElement; if (element != null) { Popup.Parent = element.Parent as FrameworkElement; if (Popup.Parent != null) { AnalysisCountryViewer analysisCountryViewer = new AnalysisCountryViewer(countryName); analysisCountryViewer.Closed += analysisCountryViewer_Closed; analysisCountryViewer.DataContext = this.DataContext; analysisCountryViewer.MaxWidth = 990; Popup.Content = analysisCountryViewer; Popup.Show(); } } } } } catch (Exception ex) { MessageBox.Show("There was a problem loading the selected custom analysis. Exception: " + ex.Message, "Problem", MessageBoxButton.OK, MessageBoxImage.Asterisk); } }