private void OpenButton_Click(object sender, RoutedEventArgs e) { if (TeamOb.Change) { MessageBoxResult result = MessageBox.Show("Сохранить изменения?", "Сообщение", MessageBoxButton.YesNo, MessageBoxImage.Information); if (result == MessageBoxResult.Yes) { Save(TeamOb); } } OpenFileDialog open_dialog = new OpenFileDialog(); if (open_dialog.ShowDialog() == true) { TeamObservable.Load(open_dialog.FileName, ref TeamOb); TeamOb.CollectionChanged += CollectionChangedEventHandler; this.DataContext = TeamOb; LeftListBox.ItemsSource = TeamOb; ListCollectionView CollectionView = new ListCollectionView(TeamOb); CollectionView.Filter = TeamOb.FilterByResearcher; RightListBox.ItemsSource = CollectionView; } }
private void FileMenu_Open_Clicked(object sender, RoutedEventArgs e) { Save_ToFile(); Microsoft.Win32.OpenFileDialog ofd = new Microsoft.Win32.OpenFileDialog(); if (ofd.ShowDialog() == true) { TeamObservable.Load(ofd.FileName, ref team); Update_Content(); DataContext = team; } }
//------------------ // Command handlers //------------------ private void OpenCommandHandler(object sender, ExecutedRoutedEventArgs e) { Microsoft.Win32.OpenFileDialog dlg = new Microsoft.Win32.OpenFileDialog(); dlg.Filter = "TeamObservable serialized object (*teamobservable)|*.teamobservable|All(*.*)|*.*"; dlg.FilterIndex = 0; dlg.CheckFileExists = true; if (dlg.ShowDialog() == true) { if (ProceedWithCollectionReplacement()) { TeamObservable.Load(dlg.FileName, ref team); // Here is no potential exception, but the file could be not opened properly. // Need a messagebox here. DataContext = team; } } }