private void savetoFileHelper(Document window) { System.Windows.Forms.SaveFileDialog fileDialog = new System.Windows.Forms.SaveFileDialog(); var tabitem = tabControl.Items.GetItemAt(windows.IndexOf(window)) as TabItem; fileDialog.Title = "存为"; fileDialog.Filter = "数据文件(*.data)|*.data"; fileDialog.FileName = ((ContentControl)tabitem.Header).Content + ".data"; if (fileDialog.ShowDialog() == System.Windows.Forms.DialogResult.OK) { string filePath = fileDialog.FileName; if (window.saveFile(filePath)) { MessageBox.Show("保存成功"); if (window.FilePath == null) { window.FilePath = filePath; ((ContentControl)tabitem.Header).Content = Path.GetFileNameWithoutExtension(filePath); } } else { MessageBox.Show("保存失败"); } } }
//保存文件 private void saveFileHelper(Document window) { if (window.FilePath == null) { savetoFileHelper(window); return; } if (MessageBox.Show(Path.GetFileNameWithoutExtension(window.FilePath) + ":确定覆盖原文件吗?", "提示", MessageBoxButton.YesNo, MessageBoxImage.Warning) == MessageBoxResult.No) { return; } if (window.saveFile(window.FilePath)) { MessageBox.Show("保存成功"); } else { MessageBox.Show("保存失败"); } }