private void FormMain_Loaded(object sender, RoutedEventArgs e) { this.Title = this.Title.Replace("Finance", ConfigurationManager.AppSettings["copyright"]); menuTableMap.ForEach(menu => { StackPanel stackPanel = null; if (stackPanelMap.ContainsKey(MENU_LIST_PREFIX + menu.group)) { stackPanel = stackPanelMap[MENU_LIST_PREFIX + menu.group]; } else { stackPanel = MainMenuTab.FindName(MENU_LIST_PREFIX + menu.group) as StackPanel; if (stackPanel != null) { stackPanelMap.Add(MENU_LIST_PREFIX + menu.group, stackPanel); } } if (stackPanel != null) { MetroExpander metroExpander = new MetroExpander(); metroExpander.Name = menu.name; metroExpander.Header = menu.header; MainMenuTab.RegisterName(menu.name, metroExpander); stackPanel.Children.Add(metroExpander); } }); foreach (var kv in stackPanelMap) { dalegateMenu(kv.Value); } }
FinanceForm FindForm(string name) { var me = MainMenuTab.FindName("tab_" + name) as MetroTabItem; if (me != null) { me.IsSelected = true; return(me.Content as FinanceForm); } return(null); }
MetroTabControl FindMetroTabControl(string menu) { MetroExpander me = MainMenuTab.FindName(menu) as MetroExpander; if (me == null) { return(null); } var name = (me.Parent as FrameworkElement).Name; var tabName = name.Replace(MENU_LIST_PREFIX, SUB_TAB_PREFIX); return(MainMenuTab.FindName(tabName) as MetroTabControl); }
void ShowForm(string header, string name, FinanceForm form) { var tabControl = FindMetroTabControl(name); if (tabControl != null) { var mainTabItem = FindMainTabItem(tabControl); if (null != mainTabItem) { mainTabItem.IsSelected = true; var tabName = SUB_TAB_PREFIX + name; var me = MainMenuTab.FindName(tabName) as MetroTabItem; if (me != null) { me.IsSelected = true; return; } if (form is FormUdefReport) { form.Name = name; var frmUdfReport = form as FormUdefReport; frmUdfReport.xTitle = header; frmUdfReport.ShowSelectedItemEvent += (id) => { var frmVoucher = FindForm("voucher_input") as FormVoucher; if (frmVoucher == null) { frmVoucher = new FormVoucher(); } frmVoucher.VoucherId = id; ShowForm("凭证录入", "voucher_input", frmVoucher); }; } MetroTabItem tabItem = new MetroTabItem(); tabItem.Header = header; tabItem.Content = form; tabItem.Name = tabName; tabControl.Items.Add(tabItem); MainMenuTab.RegisterName(tabName, tabItem); tabItem.IsSelected = true; tabItem.ButtonClick += TabItem_ButtonClick; } } }
private void FormMain_SizeChanged(object sender, SizeChangedEventArgs e) { foreach (var kv in stackPanelMap) { var tabName = kv.Key.Replace(MENU_LIST_PREFIX, SUB_TAB_PREFIX); var tabCtrl = MainMenuTab.FindName(tabName) as MetroTabControl; foreach (MetroTabItem item in tabCtrl.Items) { var frm = item.Content; if (frm != null && frm is FinanceForm) { (frm as FinanceForm).OnSizeChanged(e); } } } }