private void MenuItem_Click(object sender, RoutedEventArgs e) { string itemText = null; if (sender is MenuItem) { itemText = (sender as MenuItem).Header as string; } if (itemText == "Test") { return; } else if (itemText == "Focus") { this.TabControl1.SelectedItem = TabItem1; this.TabControl1.SelectedIndex = 1; UpdateLayout(); TabItem1.Focusable = true; TabItem1.IsEnabled = true; TabItem1.Focus(); this.Canvas1.Focusable = true; this.Canvas1.IsEnabled = true; var bb = Keyboard.Focus(this.Canvas1); var xx = this.Canvas1.Focus(); } else if (itemText == "Exit") { this.Close(); } }
private void AddToDockPanel(string s1, string s2, string s3) { string name = s1, pop = s2, feedType = s3; try { if (name != "" && pop != "" && feedType != "") { if (feedType == "Травоядный") { TabItem0.Focus(); var newHerb = new HerbivorousAnimal(name, Convert.ToInt32(pop)); var herbType = new AnimalType(newHerb); _herbList.Add(newHerb); DockPanelHerbivorous.Children.Add(herbType); } if (feedType == "Плотоядный") { TabItem1.Focus(); var newCarn = new CarnivorousAnimal(name, Convert.ToInt32(pop)); var carnType = new AnimalType(newCarn); _carnList.Add(newCarn); DockPanelCarnivorous.Children.Add(carnType); } if (feedType == "Всеядный") { TabItem2.Focus(); var newOmniv = new OmnivorousAnimal(name, Convert.ToInt32(pop)); var omnivType = new AnimalType(newOmniv); _omnivList.Add(newOmniv); DockPanelOmnivorous.Children.Add(omnivType); } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }