private void OnAddSaveClicked(object sender, RoutedEventArgs e) { OpenFileDialog fileDialog = new OpenFileDialog(); fileDialog.Title = "Add Generation III Save"; fileDialog.Filter = "GBA and GameCube Saves (*.sav, *.gci)|*.sav;*.gci|GBA Saves (*.sav)|*.sav|GameCube Saves (*.gci)|*.gci|All Files (*.*)|*.*"; var result = fileDialog.ShowDialog(this); if (result.HasValue && result.Value) { string filePath = fileDialog.FileName; filePath = System.IO.Path.GetFullPath(filePath); foreach (ListViewItem item in gameSaves) { GameSaveFileInfo save = item.Tag as GameSaveFileInfo; if (filePath.ToLower() == System.IO.Path.GetFullPath(save.FilePath).ToLower()) { TriggerMessageBox.Show(this, "This game save already exists", "Already Exists"); return; } } try { FileInfo fileInfo = new FileInfo(filePath); GameSaveFileInfo gameSaveFile; GameTypes gameType = GameTypes.Any; bool isJapanese = false; if (fileInfo.Length == 131072 || fileInfo.Length == 65536 || fileInfo.Length == 139264) { var results = SelectGameTypeFullWindow.ShowDialog(this, false); if (results != null) { gameType = results.GameType; isJapanese = results.IsJapanese; } } gameSaveFile = PokeManager.MakeNewGameSaveFileInfo(filePath, gameType, isJapanese); ListViewItem listViewItem = new ListViewItem(); FillListViewItem(gameSaveFile, listViewItem); gameSaves.Add(listViewItem); listViewGameSaves.SelectedIndex = listViewGameSaves.Items.Count - 1; // Hackish thing to make sure the list view is always scrolled at the bottom when adding a new box //http://stackoverflow.com/questions/211971/scroll-wpf-listview-to-specific-line /*VirtualizingStackPanel vsp = * (VirtualizingStackPanel)typeof(ItemsControl).InvokeMember("_itemsHost", * BindingFlags.Instance | BindingFlags.GetField | BindingFlags.NonPublic, null, * listViewGameSaves, null); * double scrollHeight = vsp.ScrollOwner.ScrollableHeight; * vsp.SetVerticalOffset(vsp.ScrollOwner.ScrollableHeight * 2);*/ listViewGameSaves.ScrollIntoView(listViewGameSaves.SelectedItem); ((Control)listViewGameSaves.SelectedItem).Focus(); } catch (Exception ex) { MessageBoxResult result2 = TriggerMessageBox.Show(this, "Error loading game save file. Would you like to see the error?", "Read Error", MessageBoxButton.YesNo); if (result2 == MessageBoxResult.Yes) { ErrorMessageBox.Show(ex); } } } }