protected override void OnStartup(StartupEventArgs e) { base.OnStartup(e); DispatcherUnhandledException += (s, a) => { MessageBox.Show(a.Exception.Message, "Error", MessageBoxButton.OK, MessageBoxImage.Error); }; LibTorrentAdapter adapter = new LibTorrentAdapter(); var viewModel = new MainWindowViewModel(adapter); MainWindow window = new MainWindow(); window.DataContext = viewModel; window.Closed += (s, a) => { adapter.Dispose(); }; window.Show(); }
public MainWindowViewModel(LibTorrentAdapter adapter) { if (adapter == null) { throw new ArgumentNullException("adapter"); } _adapter = adapter; IpAddress = "0.0.0.0"; IpPort = 6881; AreSettingsEnabled = true; EnterUrlExampleCommand = new RelayCommand(ExecuteEnterUrlExampleCommand); DownloadToCommand = new RelayCommand(ExecuteDownloadToCommand, CanExecuteDownloadToCommand); PauseCommand = new RelayCommand(ExecutePauseCommand, CanExecutePauseCommand); ResumeCommand = new RelayCommand(ExecuteResumeCommand, CanExecuteResumeCommand); }