private void item_Unloaded(object sender, RoutedEventArgs e) { try { if (sender is Telerik.Windows.Controls.RadDocumentPane) { Telerik.Windows.Controls.RadDocumentPane tab = sender as Telerik.Windows.Controls.RadDocumentPane; if (tab.Content is UserControl) { if ((tab.Content as UserControl).DataContext != null) { ((ICleanup)(tab.Content as UserControl).DataContext).Cleanup(); } } tab.Unloaded -= new RoutedEventHandler(item_Unloaded); } } catch (Exception ex) { MessageCustomize.Show(ex.Message); } }
//Load menu by name when click on left menu bar private void OnChangeMenuItemMessage(string menuName) { Telerik.Windows.Controls.RadDocumentPane item; for (int i = 0; i < rpgMain.Items.Count; i++) { if (rpgMain.Items[i] is Telerik.Windows.Controls.RadDocumentPane) { if ((rpgMain.Items[i] as Telerik.Windows.Controls.RadDocumentPane).Tag.ToString() == menuName) { rpgMain.SelectedIndex = i; return; } } } switch (menuName) { //Training case ViewTypes.ListClassView: item = new Telerik.Windows.Controls.RadDocumentPane(); item.Tag = ViewTypes.ListClassView; item.Header = "Danh sách lớp học"; item.Content = new ListClassView(); break; case ViewTypes.ListDepartmentView: item = new Telerik.Windows.Controls.RadDocumentPane(); item.Tag = ViewTypes.ListDepartmentView; item.Header = "Danh sách khoa"; item.Content = new ListDepartmentView(); break; case ViewTypes.ListRoomView: item = new Telerik.Windows.Controls.RadDocumentPane(); item.Tag = ViewTypes.ListRoomView; item.Header = "Danh sách phòng học"; item.Content = new ListRoomView(); break; case ViewTypes.ListSubjectView: item = new Telerik.Windows.Controls.RadDocumentPane(); item.Tag = ViewTypes.ListSubjectView; item.Header = "Danh sách phòng học"; item.Content = new ListSubjectView(); break; case ViewTypes.ListTrainingView: item = new Telerik.Windows.Controls.RadDocumentPane(); item.Tag = ViewTypes.ListTrainingView; item.Header = "Danh sách phòng học"; item.Content = new ListTrainingView(); break; default: throw new NotImplementedException(); } if (item != null) { item.Unloaded += new RoutedEventHandler(item_Unloaded); rpgMain.Items.Add(item); } }
private void View_SetFocus(object sender, EventArgs e) { try { if (sender != null) { if (sender is int) { //0 Clear tab, 1 Show all menu, 2 Change theme switch (Convert.ToInt32(sender)) { case 0: foreach (var item in rpgMain.Items) { if (item is Telerik.Windows.Controls.RadDocumentPane) { Telerik.Windows.Controls.RadDocumentPane tab = item as Telerik.Windows.Controls.RadDocumentPane; if (tab.Content is UserControl) { if ((tab.Content as UserControl).DataContext != null) { ((ICleanup)(tab.Content as UserControl).DataContext).Cleanup(); } } tab.Unloaded -= new RoutedEventHandler(item_Unloaded); } } rpgMain.Items.Clear(); break; case 1: foreach (var item in robCategories.Items) { CheckMenuItem(item, null, true); } break; case 2: ChangeTheme(); break; default: break; } } //Change menu when user is not admin if (sender is List <string> ) { List <string> lstMenu = sender as List <string>; foreach (var item in robCategories.Items) { CheckMenuItem(item, lstMenu, false); } foreach (var item in robCategories.Items) { if (item is Telerik.Windows.Controls.RadOutlookBarItem) { if ((item as Telerik.Windows.Controls.RadOutlookBarItem).Visibility == Visibility.Visible) { robCategories.SelectedItem = item; return; } } } } } } catch (Exception ex) { MessageCustomize.Show(ex.Message); } }
//Load menu by name when click on left menu bar private void OnChangeMenuItemMessage(string menuName) { Telerik.Windows.Controls.RadDocumentPane item; for (int i = 0; i < rpgMain.Items.Count; i++) { if (rpgMain.Items[i] is Telerik.Windows.Controls.RadDocumentPane) { if ((rpgMain.Items[i] as Telerik.Windows.Controls.RadDocumentPane).Tag.ToString() == menuName) { rpgMain.SelectedIndex = i; return; } } } switch (menuName) { //Training case ViewTypes.ListClassView: item = new Telerik.Windows.Controls.RadDocumentPane(); item.Tag = ViewTypes.ListClassView; item.Header = "Danh sách lớp học"; item.Content = new ListClassView(); break; case ViewTypes.ListDepartmentView: item = new Telerik.Windows.Controls.RadDocumentPane(); item.Tag = ViewTypes.ListDepartmentView; item.Header = "Danh sách khoa"; item.Content = new ListDepartmentView(); break; case ViewTypes.ListRoomView: item = new Telerik.Windows.Controls.RadDocumentPane(); item.Tag = ViewTypes.ListRoomView; item.Header = "Danh sách phòng học"; item.Content = new ListRoomView(); break; case ViewTypes.ListSubjectView: item = new Telerik.Windows.Controls.RadDocumentPane(); item.Tag = ViewTypes.ListSubjectView; item.Header = "Danh sách phòng học"; item.Content = new ListSubjectView(); break; case ViewTypes.ListTrainingView: item = new Telerik.Windows.Controls.RadDocumentPane(); item.Tag = ViewTypes.ListTrainingView; item.Header = "Danh sách phòng học"; item.Content = new ListTrainingView(); break; default: throw new NotImplementedException(); } if (item != null) { item.Unloaded += new RoutedEventHandler(item_Unloaded); rpgMain.Items.Add(item); } }