Wpf Dialogs -

if (_dialogService.ShowConfirmation("Save changes?", "Confirm")) // Save logic

// Generic dialog window public partial class GenericDialog<T> : Window

private void CancelButton_Click(object sender, RoutedEventArgs e) WPF Dialogs

// Save to saveFileDialog.FileName

if (dialog.ShowDialog() == DialogResult.OK) if (_dialogService

private Type GetWindowTypeForViewModel(Type viewModelType)

Dispatcher.Invoke(() => ProgressBar.Value = (double)current / total * 100; MessageText.Text = message; ); if (_dialogService.ShowConfirmation("Save changes?"

public bool Confirmed get; set; public T Data get; set;

string fileContent = File.ReadAllText(openFileDialog.FileName);

public ProgressDialog(string title) InitializeComponent(); Title = title; Owner = Application.Current.MainWindow; public void UpdateProgress(int current, int total, string message)

For proper MVVM separation, avoid code-behind: Interface for Dialog Service public interface IDialogService

目次