public CockPit() { InitializeComponent(); DataContext = App.CurrentViewModel; vm = App.CurrentViewModel; listbox.SelectedItem = listbox.Items[0]; }
public Category(string catName, NerdQuizViewModel vm) { Text = catName; Q1 = new Question(100, this); Q2 = new Question(200, this); Q3 = new Question(300, this); Q4 = new Question(600, this); Q5 = new Question(1000, this); }
private void LoadQuestionsClick(object sender, RoutedEventArgs e) { try { if (sb == null || MessageBox.Show("Dadurch wird aktuelle Runde beendet, sicher?", "Achtung", MessageBoxButton.OKCancel, MessageBoxImage.Question) == MessageBoxResult.OK) { var dialog = new System.Windows.Forms.OpenFileDialog(); dialog.Filter = "xml Dateien|*.xml"; dialog.InitialDirectory = @"C:\"; dialog.Title = "XML wählen"; if (dialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { if (sb != null) { sb.Close(); sb = null; } var serializer = new XmlSerializer(typeof(NerdQuizViewModel)); using (var sr = new StreamReader(dialog.FileName)) { vm = (NerdQuizViewModel)serializer.Deserialize(sr); vm.P1 = App.CurrentViewModel.P1; vm.P2 = App.CurrentViewModel.P2; vm.P3 = App.CurrentViewModel.P3; vm.P4 = App.CurrentViewModel.P4; vm.P5 = App.CurrentViewModel.P5; foreach (var cat in vm.Categories) { foreach (var q in cat.Questions) { q.CategoryText = cat.Text; } } vm.CurrentQuestion = vm.Cat1.Q1; App.CurrentViewModel = vm; DataContext = vm; } } } } catch (Exception ex) { MessageBox.Show(ex.Message); } }
public App() { CurrentViewModel = new NerdQuizViewModel(); }