Replace DelegateCommand by RelayCommand from MVVC framework

This commit is contained in:
Adrien Allard committed 2018-12-06 18:46:06 +01:00
1 parent 5c933fc569
commit 5637aa1f74
6 files changed
+17 -60

No files matched your search

@@ -1,46 +0,0 @@
// <copyright file="DelegateCommand.cs" company="AAllard">License: http://www.gnu.org/licenses/gpl.html GPL version 3.</copyright>
namespace FileConverter.Commands
{
using System;
using System.Windows.Input;
public class DelegateCommand : ICommand
{
private Action executeMethod;
private Func<bool> canExecuteMethod;
public DelegateCommand(Action executeMethod)
{
if (executeMethod == null)
{
throw new ArgumentNullException(nameof(executeMethod));
}
this.executeMethod = executeMethod;
}
public DelegateCommand(Action executeMethod, Func<bool> canExecuteMethod)
{
this.executeMethod = executeMethod;
this.canExecuteMethod = canExecuteMethod;
}
public event EventHandler CanExecuteChanged;
public bool CanExecute(object parameter)
{
if (this.canExecuteMethod != null)
{
return this.canExecuteMethod.Invoke();
}
return true;
}
public void Execute(object parameter)
{
this.executeMethod.Invoke();
}
}
}
@@ -136,7 +136,6 @@
<SubType>Designer</SubType>
</ApplicationDefinition>
<Compile Include="ApplicationTerminateArgs.cs" />
<Compile Include="Commands\DelegateCommand.cs" />
<Compile Include="Commands\OpenUrlCommand.cs" />
<Compile Include="Controls\ConversionJobControl.xaml.cs">
<DependentUpon>ConversionJobControl.xaml</DependentUpon>
@@ -11,6 +11,7 @@ namespace FileConverter.ViewModels
using FileConverter.Services;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Ioc;
/// <summary>
@@ -27,7 +28,7 @@ namespace FileConverter.ViewModels
/// </summary>
public class HelpViewModel : ViewModelBase
{
private DelegateCommand quitCommand;
private RelayCommand quitCommand;
/// <summary>
/// Initializes a new instance of the HelpViewModel class.
@@ -49,7 +50,7 @@ namespace FileConverter.ViewModels
{
if (this.quitCommand == null)
{
this.quitCommand = new DelegateCommand(() => System.Windows.Application.Current.Shutdown());
this.quitCommand = new RelayCommand(() => System.Windows.Application.Current.Shutdown());
}
return this.quitCommand;
@@ -10,6 +10,7 @@ namespace FileConverter.ViewModels
using FileConverter.Services;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Ioc;
/// <summary>
@@ -29,7 +30,8 @@ namespace FileConverter.ViewModels
private string informationMessage;
private ObservableCollection<ConversionJob> conversionJobs;
private DelegateCommand showSettingsCommand;
private RelayCommand showSettingsCommand;
private RelayCommand showDiagnosticsCommand;
/// <summary>
/// Initializes a new instance of the MainViewModel class.
@@ -90,7 +92,7 @@ namespace FileConverter.ViewModels
{
if (this.showSettingsCommand == null)
{
this.showSettingsCommand = new DelegateCommand(() => SimpleIoc.Default.GetInstance<INavigationService>().NavigateTo(Pages.Settings));
this.showSettingsCommand = new RelayCommand(() => SimpleIoc.Default.GetInstance<INavigationService>().NavigateTo(Pages.Settings));
}
return this.showSettingsCommand;
@@ -101,12 +103,12 @@ namespace FileConverter.ViewModels
{
get
{
if (this.showSettingsCommand == null)
if (this.showDiagnosticsCommand == null)
{
this.showSettingsCommand = new DelegateCommand(() => SimpleIoc.Default.GetInstance<INavigationService>().NavigateTo(Pages.Diagnostics));
this.showDiagnosticsCommand = new RelayCommand(() => SimpleIoc.Default.GetInstance<INavigationService>().NavigateTo(Pages.Diagnostics));
}
return this.showSettingsCommand;
return this.showDiagnosticsCommand;
}
}
@@ -45,7 +45,7 @@ namespace FileConverter.ViewModels
private bool displaySeeChangeLogLink = true;
private OpenUrlCommand openUrlCommand;
private DelegateCommand getChangeLogContentCommand;
private RelayCommand getChangeLogContentCommand;
private RelayCommand movePresetUpCommand;
private RelayCommand movePresetDownCommand;
private RelayCommand addNewPresetCommand;
@@ -223,7 +223,7 @@ namespace FileConverter.ViewModels
{
if (this.getChangeLogContentCommand == null)
{
this.getChangeLogContentCommand = new DelegateCommand(this.DownloadChangeLogAction);
this.getChangeLogContentCommand = new RelayCommand(this.DownloadChangeLogAction);
}
return this.getChangeLogContentCommand;
@@ -11,6 +11,7 @@ namespace FileConverter.ViewModels
using FileConverter.Services;
using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Ioc;
/// <summary>
@@ -30,8 +31,8 @@ namespace FileConverter.ViewModels
private UpgradeVersionDescription upgradeVersionDescription;
private string releaseNoteContent;
private DelegateCommand downloadInstallerCommand;
private DelegateCommand launchInstallerCommand;
private RelayCommand downloadInstallerCommand;
private RelayCommand launchInstallerCommand;
/// <summary>
/// Initializes a new instance of the UpgradeViewModel class.
@@ -59,7 +60,7 @@ namespace FileConverter.ViewModels
{
if (this.downloadInstallerCommand == null)
{
this.downloadInstallerCommand = new DelegateCommand(this.ExecuteDownloadInstallerCommand);
this.downloadInstallerCommand = new RelayCommand(this.ExecuteDownloadInstallerCommand);
}
return this.downloadInstallerCommand;
@@ -72,7 +73,7 @@ namespace FileConverter.ViewModels
{
if (this.launchInstallerCommand == null)
{
this.launchInstallerCommand = new DelegateCommand(this.ExecuteLaunchInstallerCommand);
this.launchInstallerCommand = new RelayCommand(this.ExecuteLaunchInstallerCommand);
}
return this.launchInstallerCommand;