diff --git a/Application/FileConverter/App.config b/Application/FileConverter/App.config index 8aff8eb..4165a81 100644 --- a/Application/FileConverter/App.config +++ b/Application/FileConverter/App.config @@ -1,14 +1,26 @@ - + - + - + - - + + + + + + + + + + + + + + diff --git a/Application/FileConverter/Application.xaml b/Application/FileConverter/Application.xaml index d0b126d..9d54817 100644 --- a/Application/FileConverter/Application.xaml +++ b/Application/FileConverter/Application.xaml @@ -17,9 +17,6 @@ - - - diff --git a/Application/FileConverter/Application.xaml.cs b/Application/FileConverter/Application.xaml.cs index ce92013..eb42f30 100644 --- a/Application/FileConverter/Application.xaml.cs +++ b/Application/FileConverter/Application.xaml.cs @@ -22,12 +22,13 @@ namespace FileConverter using System.Threading; using System.Windows; + using CommunityToolkit.Mvvm.DependencyInjection; + using FileConverter.ConversionJobs; using FileConverter.Services; + using FileConverter.ViewModels; using FileConverter.Views; - - using GalaSoft.MvvmLight.Ioc; - + using Microsoft.Extensions.DependencyInjection; using Debug = FileConverter.Diagnostics.Debug; public partial class Application : System.Windows.Application @@ -77,7 +78,7 @@ namespace FileConverter this.Initialize(); // Navigate to the wanted view. - INavigationService navigationService = SimpleIoc.Default.GetInstance(); + INavigationService navigationService = Ioc.Default.GetRequiredService(); if (this.showHelp) { @@ -89,7 +90,7 @@ namespace FileConverter { navigationService.Show(Pages.Main); - IConversionService conversionService = SimpleIoc.Default.GetInstance(); + IConversionService conversionService = Ioc.Default.GetRequiredService(); conversionService.ConversionJobsTerminated += this.ConversionService_ConversionJobsTerminated; conversionService.ConvertFilesAsync(); } @@ -111,7 +112,7 @@ namespace FileConverter Debug.Log("Exit application."); - IUpgradeService upgradeService = SimpleIoc.Default.GetInstance(); + IUpgradeService upgradeService = Ioc.Default.GetRequiredService(); if (!this.isSessionEnding && upgradeService.UpgradeVersionDescription != null && upgradeService.UpgradeVersionDescription.NeedToUpgrade) { @@ -161,37 +162,36 @@ namespace FileConverter private void RegisterServices() { - if (this.TryFindResource("Settings") == null) - { - Debug.LogError("Can't retrieve conversion service."); - this.Dispatcher.BeginInvoke((Action)(() => Application.Current.Shutdown())); - } + var services = new ServiceCollection(); - if (this.TryFindResource("Locator") == null) + if (this.TryFindResource("Locator") is ViewModelLocator viewModelLocator) + { + viewModelLocator.RegisterViewModels(services); + } + else { Debug.LogError("Can't retrieve view model locator."); this.Dispatcher.BeginInvoke((Action)(() => Application.Current.Shutdown())); } - if (this.TryFindResource("Conversions") == null) + if (this.TryFindResource("Upgrade") is UpgradeService upgradeService) { - Debug.LogError("Can't retrieve conversion service."); + services.AddSingleton(upgradeService); + } + else + { + Debug.LogError("Can't retrieve Upgrade service."); this.Dispatcher.BeginInvoke((Action)(() => Application.Current.Shutdown())); } - if (this.TryFindResource("Navigation") == null) - { - Debug.LogError("Can't retrieve navigation service."); - this.Dispatcher.BeginInvoke((Action)(() => Application.Current.Shutdown())); - } + services + .AddSingleton() + .AddSingleton() + .AddSingleton(); - if (this.TryFindResource("Upgrade") == null) - { - Debug.LogError("Can't retrieve navigation service."); - this.Dispatcher.BeginInvoke((Action)(() => Application.Current.Shutdown())); - } + Ioc.Default.ConfigureServices(services.BuildServiceProvider()); - INavigationService navigationService = SimpleIoc.Default.GetInstance(); + INavigationService navigationService = Ioc.Default.GetRequiredService(); navigationService.RegisterPage(Pages.Help, false, true); navigationService.RegisterPage(Pages.Main, false, true); @@ -228,7 +228,7 @@ namespace FileConverter return; } - ISettingsService settingsService = SimpleIoc.Default.GetInstance(); + ISettingsService settingsService = Ioc.Default.GetRequiredService(); // Parse arguments. bool quitAfterStartup = false; @@ -364,7 +364,7 @@ namespace FileConverter // Check for upgrade. if (settingsService.Settings.CheckUpgradeAtStartup) { - IUpgradeService upgradeService = SimpleIoc.Default.GetInstance(); + IUpgradeService upgradeService = Ioc.Default.GetRequiredService(); upgradeService.NewVersionAvailable += this.UpgradeService_NewVersionAvailable; upgradeService.CheckForUpgrade(); } @@ -383,7 +383,7 @@ namespace FileConverter if (conversionPreset != null) { - IConversionService conversionService = SimpleIoc.Default.GetInstance(); + IConversionService conversionService = Ioc.Default.GetRequiredService(); // Create conversion jobs. Debug.Log("Create jobs for conversion preset: '{0}'", conversionPreset.FullName); @@ -409,18 +409,18 @@ namespace FileConverter private void UpgradeService_NewVersionAvailable(object sender, UpgradeVersionDescription e) { - SimpleIoc.Default.GetInstance().Show(Pages.Upgrade); + Ioc.Default.GetRequiredService().Show(Pages.Upgrade); - IUpgradeService upgradeService = SimpleIoc.Default.GetInstance(); + IUpgradeService upgradeService = Ioc.Default.GetRequiredService(); upgradeService.NewVersionAvailable -= this.UpgradeService_NewVersionAvailable; } private void ConversionService_ConversionJobsTerminated(object sender, ConversionJobsTerminatedEventArgs e) { - IConversionService conversionService = SimpleIoc.Default.GetInstance(); + IConversionService conversionService = Ioc.Default.GetRequiredService(); conversionService.ConversionJobsTerminated -= this.ConversionService_ConversionJobsTerminated; - ISettingsService settingsService = SimpleIoc.Default.GetInstance(); + ISettingsService settingsService = Ioc.Default.GetRequiredService(); if (!settingsService.Settings.ExitApplicationWhenConversionsFinished) { diff --git a/Application/FileConverter/ConversionJobs/ConversionJob.cs b/Application/FileConverter/ConversionJobs/ConversionJob.cs index 9c51027..1f633ec 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob.cs @@ -6,11 +6,11 @@ namespace FileConverter.ConversionJobs using System.ComponentModel; using System.Runtime.CompilerServices; using System.Windows.Input; + + using CommunityToolkit.Mvvm.Input; using FileConverter.Diagnostics; - using GalaSoft.MvvmLight.Command; - public class ConversionJob : INotifyPropertyChanged { private float progress = 0f; @@ -192,7 +192,7 @@ namespace FileConverter.ConversionJobs } } - protected virtual bool IsCancelable => this.State == ConversionState.InProgress; + protected virtual bool IsCancelable() => this.State == ConversionState.InProgress; protected string[] OutputFilePaths { @@ -363,7 +363,7 @@ namespace FileConverter.ConversionJobs public virtual void Cancel() { - if (!this.IsCancelable) + if (!this.IsCancelable()) { return; } diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_Excel.cs b/Application/FileConverter/ConversionJobs/ConversionJob_Excel.cs index f900a85..f03886c 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_Excel.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_Excel.cs @@ -28,7 +28,7 @@ namespace FileConverter.ConversionJobs protected override ApplicationName Application => ApplicationName.Excel; - protected override bool IsCancelable => false; + protected override bool IsCancelable() => false; protected override int GetOutputFilesCount() { diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_Office.cs b/Application/FileConverter/ConversionJobs/ConversionJob_Office.cs index 567dd63..c9ca3e2 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_Office.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_Office.cs @@ -26,7 +26,7 @@ namespace FileConverter.ConversionJobs get; } - protected override bool IsCancelable => false; + protected override bool IsCancelable() => false; protected override void Initialize() { diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_PowerPoint.cs b/Application/FileConverter/ConversionJobs/ConversionJob_PowerPoint.cs index dc88f0c..3242284 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_PowerPoint.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_PowerPoint.cs @@ -29,7 +29,7 @@ namespace FileConverter.ConversionJobs protected override ApplicationName Application => ApplicationName.PowerPoint; - protected override bool IsCancelable => false; + protected override bool IsCancelable() => false; protected override int GetOutputFilesCount() { diff --git a/Application/FileConverter/ConversionJobs/ConversionJob_Word.cs b/Application/FileConverter/ConversionJobs/ConversionJob_Word.cs index 36d3e54..ac1c1f3 100644 --- a/Application/FileConverter/ConversionJobs/ConversionJob_Word.cs +++ b/Application/FileConverter/ConversionJobs/ConversionJob_Word.cs @@ -28,7 +28,7 @@ namespace FileConverter.ConversionJobs protected override ApplicationName Application => ApplicationName.Word; - protected override bool IsCancelable => false; + protected override bool IsCancelable() => false; protected override int GetOutputFilesCount() { diff --git a/Application/FileConverter/ConversionPreset/ConversionPreset.cs b/Application/FileConverter/ConversionPreset/ConversionPreset.cs index 693892d..1204ea6 100644 --- a/Application/FileConverter/ConversionPreset/ConversionPreset.cs +++ b/Application/FileConverter/ConversionPreset/ConversionPreset.cs @@ -6,11 +6,11 @@ namespace FileConverter using System.Collections.Generic; using System.Globalization; using System.Xml.Serialization; + + using CommunityToolkit.Mvvm.ComponentModel; using FileConverter.Controls; - using GalaSoft.MvvmLight; - [XmlRoot] [XmlType] public class ConversionPreset : ObservableObject, IXmlSerializable @@ -109,7 +109,7 @@ namespace FileConverter set { this.shortName = value; - this.RaisePropertyChanged(); + this.OnPropertyChanged(); } } @@ -129,7 +129,7 @@ namespace FileConverter { this.outputType = value; this.InitializeDefaultSettings(this.outputType); - this.RaisePropertyChanged(); + this.OnPropertyChanged(); this.CoerceInputTypes(); } } @@ -157,7 +157,7 @@ namespace FileConverter this.inputTypes[index] = this.inputTypes[index].ToLowerInvariant(); } - this.RaisePropertyChanged(); + this.OnPropertyChanged(); } } @@ -172,7 +172,7 @@ namespace FileConverter set { this.inputPostConversionAction = value; - this.RaisePropertyChanged(); + this.OnPropertyChanged(); } } @@ -216,7 +216,7 @@ namespace FileConverter } } - this.RaisePropertyChanged(nameof(this.Settings)); + this.OnPropertyChanged(nameof(this.Settings)); } } @@ -231,7 +231,7 @@ namespace FileConverter set { this.outputFileNameTemplate = value; - this.RaisePropertyChanged(); + this.OnPropertyChanged(); } } @@ -268,7 +268,7 @@ namespace FileConverter } } - this.RaisePropertyChanged(); + this.OnPropertyChanged(); } } @@ -308,14 +308,14 @@ namespace FileConverter } this.inputTypes.Add(inputType); - this.RaisePropertyChanged(nameof(this.InputTypes)); + this.OnPropertyChanged(nameof(this.InputTypes)); } public void RemoveInputType(string inputType) { if (this.inputTypes.Remove(inputType)) { - this.RaisePropertyChanged(nameof(this.InputTypes)); + this.OnPropertyChanged(nameof(this.InputTypes)); } } @@ -348,7 +348,7 @@ namespace FileConverter this.settings[settingsKey] = value; - this.RaisePropertyChanged(nameof(this.Settings)); + this.OnPropertyChanged(nameof(this.Settings)); } public string GetSettingsValue(string settingsKey) @@ -544,7 +544,7 @@ namespace FileConverter throw new System.Exception("Missing default settings for type " + outputType); } - this.RaisePropertyChanged(nameof(this.Settings)); + this.OnPropertyChanged(nameof(this.Settings)); } private void InitializeSettingsValue(string settingsKey, string value, bool force = false) diff --git a/Application/FileConverter/FileConverter.csproj b/Application/FileConverter/FileConverter.csproj index 636a157..166da5d 100644 --- a/Application/FileConverter/FileConverter.csproj +++ b/Application/FileConverter/FileConverter.csproj @@ -69,18 +69,8 @@ true - - ..\..\packages\CommonServiceLocator.2.0.7\lib\net48\CommonServiceLocator.dll - True - - - ..\..\packages\MvvmLightLibs.5.4.1.1\lib\net45\GalaSoft.MvvmLight.dll - - - ..\..\packages\MvvmLightLibs.5.4.1.1\lib\net45\GalaSoft.MvvmLight.Extras.dll - - - ..\..\packages\MvvmLightLibs.5.4.1.1\lib\net45\GalaSoft.MvvmLight.Platform.dll + + ..\..\packages\CommunityToolkit.Mvvm.8.2.2\lib\netstandard2.0\CommunityToolkit.Mvvm.dll ..\..\packages\Magick.NET-Q16-AnyCPU.13.5.0\lib\netstandard20\Magick.NET-Q16-AnyCPU.dll @@ -93,6 +83,15 @@ ..\..\Middleware\Markdown.Xaml.dll + + ..\..\packages\Microsoft.Bcl.AsyncInterfaces.8.0.0\lib\net462\Microsoft.Bcl.AsyncInterfaces.dll + + + ..\..\packages\Microsoft.Extensions.DependencyInjection.8.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.dll + + + ..\..\packages\Microsoft.Extensions.DependencyInjection.Abstractions.8.0.0\lib\net462\Microsoft.Extensions.DependencyInjection.Abstractions.dll + ..\..\packages\Microsoft.Office.Interop.Excel.15.0.4795.1000\lib\net20\Microsoft.Office.Interop.Excel.dll True @@ -105,6 +104,9 @@ ..\..\packages\Microsoft.Office.Interop.Word.15.0.4797.1003\lib\net20\Microsoft.Office.Interop.Word.dll True + + ..\..\packages\Microsoft.Xaml.Behaviors.Wpf.1.1.77\lib\net462\Microsoft.Xaml.Behaviors.dll + ..\..\packages\Office.12.0.0\lib\net40\Office.dll True @@ -118,12 +120,29 @@ ..\..\packages\SharpShell.2.7.2\lib\net40-client\SharpShell.dll - - - - - ..\..\packages\MvvmLightLibs.5.4.1.1\lib\net45\System.Windows.Interactivity.dll + + ..\..\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll + + ..\..\packages\System.ComponentModel.Annotations.5.0.0\lib\net461\System.ComponentModel.Annotations.dll + + + + + + ..\..\packages\System.Memory.4.5.5\lib\net461\System.Memory.dll + + + + ..\..\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll + + + ..\..\packages\System.Runtime.CompilerServices.Unsafe.6.0.0\lib\net461\System.Runtime.CompilerServices.Unsafe.dll + + + ..\..\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll + + @@ -448,7 +467,9 @@ if %25errorlevel%25 leq 1 exit 0 else exit %25errorlevel%25 This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them. For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}. + + create design time data. - } - else - { - } } public ICommand CloseCommand @@ -56,7 +40,7 @@ namespace FileConverter.ViewModels private void Close(CancelEventArgs args) { - INavigationService navigationService = SimpleIoc.Default.GetInstance(); + INavigationService navigationService = Ioc.Default.GetRequiredService(); navigationService.Close(Pages.Diagnostics, args != null); } } diff --git a/Application/FileConverter/ViewModels/HelpViewModel.cs b/Application/FileConverter/ViewModels/HelpViewModel.cs index 7db5a80..32ab7cb 100644 --- a/Application/FileConverter/ViewModels/HelpViewModel.cs +++ b/Application/FileConverter/ViewModels/HelpViewModel.cs @@ -5,25 +5,16 @@ namespace FileConverter.ViewModels using System.ComponentModel; using System.Windows.Input; - using FileConverter.Services; + using CommunityToolkit.Mvvm.ComponentModel; + using CommunityToolkit.Mvvm.DependencyInjection; + using CommunityToolkit.Mvvm.Input; - using GalaSoft.MvvmLight; - using GalaSoft.MvvmLight.Command; - using GalaSoft.MvvmLight.Ioc; + using FileConverter.Services; /// /// This class contains properties that the main View can data bind to. - /// - /// Use the mvvminpc snippet to add bindable properties to this ViewModel. - /// - /// - /// You can also use Blend to data bind with the tool's support. - /// - /// - /// See http://www.galasoft.ch/mvvm - /// /// - public class HelpViewModel : ViewModelBase + public class HelpViewModel : ObservableRecipient { private RelayCommand closeCommand; @@ -32,13 +23,6 @@ namespace FileConverter.ViewModels /// public HelpViewModel() { - if (this.IsInDesignMode) - { - // Code runs in Blend --> create design time data. - } - else - { - } } public ICommand CloseCommand @@ -56,7 +40,7 @@ namespace FileConverter.ViewModels private void Close(CancelEventArgs args) { - INavigationService navigationService = SimpleIoc.Default.GetInstance(); + INavigationService navigationService = Ioc.Default.GetRequiredService(); navigationService.Close(Pages.Help, args != null); } } diff --git a/Application/FileConverter/ViewModels/InputExtension.cs b/Application/FileConverter/ViewModels/InputExtension.cs index 4299f1c..43f538e 100644 --- a/Application/FileConverter/ViewModels/InputExtension.cs +++ b/Application/FileConverter/ViewModels/InputExtension.cs @@ -4,10 +4,9 @@ namespace FileConverter.ViewModels { using System.Windows.Media; - using CommonServiceLocator; - using GalaSoft.MvvmLight; + using CommunityToolkit.Mvvm.ComponentModel; + using CommunityToolkit.Mvvm.DependencyInjection; - using FileConverter.Annotations; using FileConverter.ConversionJobs; public class InputExtension : ObservableObject @@ -56,7 +55,7 @@ namespace FileConverter.ViewModels set { this.name = value; - this.RaisePropertyChanged(); + this.OnPropertyChanged(); } } @@ -67,7 +66,7 @@ namespace FileConverter.ViewModels set { this.foregroundBrush = value; - this.RaisePropertyChanged(); + this.OnPropertyChanged(); } } @@ -78,7 +77,7 @@ namespace FileConverter.ViewModels set { this.toolTip = value; - this.RaisePropertyChanged(); + this.OnPropertyChanged(); } } @@ -86,7 +85,7 @@ namespace FileConverter.ViewModels { get { - SettingsViewModel settingsViewModel = ServiceLocator.Current.GetInstance(); + SettingsViewModel settingsViewModel = Ioc.Default.GetRequiredService(); PresetNode selectedPreset = settingsViewModel.SelectedPreset; if (selectedPreset == null) { @@ -98,7 +97,7 @@ namespace FileConverter.ViewModels set { - SettingsViewModel settingsViewModel = ServiceLocator.Current.GetInstance(); + SettingsViewModel settingsViewModel = Ioc.Default.GetRequiredService(); PresetNode selectedPreset = settingsViewModel.SelectedPreset; if (value) @@ -110,8 +109,13 @@ namespace FileConverter.ViewModels selectedPreset?.Preset.RemoveInputType(this.name.ToLowerInvariant()); } - this.RaisePropertyChanged(nameof(this.IsChecked)); + this.OnPropertyChanged(nameof(this.IsChecked)); } } + + internal void OnCategoryChanged() + { + this.OnPropertyChanged(nameof(this.IsChecked)); + } } } \ No newline at end of file diff --git a/Application/FileConverter/ViewModels/InputExtensionCategory.cs b/Application/FileConverter/ViewModels/InputExtensionCategory.cs index 8affdbe..3eaefcf 100644 --- a/Application/FileConverter/ViewModels/InputExtensionCategory.cs +++ b/Application/FileConverter/ViewModels/InputExtensionCategory.cs @@ -2,11 +2,12 @@ namespace FileConverter.ViewModels { - using CommonServiceLocator; - using GalaSoft.MvvmLight; using System.ComponentModel; using System.Collections.Generic; + using CommunityToolkit.Mvvm.ComponentModel; + using CommunityToolkit.Mvvm.DependencyInjection; + public class InputExtensionCategory : ObservableObject { private readonly List inputExtensions = new List(); @@ -24,7 +25,7 @@ namespace FileConverter.ViewModels set { this.name = value; - this.RaisePropertyChanged(); + this.OnPropertyChanged(); } } @@ -51,9 +52,9 @@ namespace FileConverter.ViewModels inputExtension.PropertyChanged += this.OnExtensionPropertyChange; - this.RaisePropertyChanged(nameof(this.InputExtensions)); - this.RaisePropertyChanged(nameof(this.InputExtensionNames)); - this.RaisePropertyChanged(nameof(this.IsChecked)); + this.OnPropertyChanged(nameof(this.InputExtensions)); + this.OnPropertyChanged(nameof(this.InputExtensionNames)); + this.OnPropertyChanged(nameof(this.IsChecked)); } } @@ -61,7 +62,7 @@ namespace FileConverter.ViewModels { get { - SettingsViewModel settingsViewModel = ServiceLocator.Current.GetInstance(); + SettingsViewModel settingsViewModel = Ioc.Default.GetRequiredService(); PresetNode selectedPreset = settingsViewModel.SelectedPreset; if (selectedPreset == null) { @@ -91,7 +92,7 @@ namespace FileConverter.ViewModels set { - SettingsViewModel settingsViewModel = ServiceLocator.Current.GetInstance(); + SettingsViewModel settingsViewModel = Ioc.Default.GetRequiredService(); PresetNode selectedPreset = settingsViewModel.SelectedPreset; foreach (string extension in this.InputExtensionNames) @@ -109,16 +110,16 @@ namespace FileConverter.ViewModels // Raise property change for extensions. foreach (InputExtension inputExtension in this.InputExtensions) { - inputExtension.RaisePropertyChanged(nameof(inputExtension.IsChecked)); + inputExtension.OnCategoryChanged(); } - this.RaisePropertyChanged(nameof(this.IsChecked)); + this.OnPropertyChanged(nameof(this.IsChecked)); } } private void OnExtensionPropertyChange(object sender, PropertyChangedEventArgs e) { - this.RaisePropertyChanged(nameof(this.IsChecked)); + this.OnPropertyChanged(nameof(this.IsChecked)); } } } \ No newline at end of file diff --git a/Application/FileConverter/ViewModels/MainViewModel.cs b/Application/FileConverter/ViewModels/MainViewModel.cs index 8c0e50f..e50a632 100644 --- a/Application/FileConverter/ViewModels/MainViewModel.cs +++ b/Application/FileConverter/ViewModels/MainViewModel.cs @@ -6,26 +6,17 @@ namespace FileConverter.ViewModels using System.ComponentModel; using System.Windows.Input; + using CommunityToolkit.Mvvm.ComponentModel; + using CommunityToolkit.Mvvm.DependencyInjection; + using CommunityToolkit.Mvvm.Input; + using FileConverter.ConversionJobs; using FileConverter.Services; - using GalaSoft.MvvmLight; - using GalaSoft.MvvmLight.Command; - using GalaSoft.MvvmLight.Ioc; - /// /// This class contains properties that the main View can data bind to. - /// - /// Use the mvvminpc snippet to add bindable properties to this ViewModel. - /// - /// - /// You can also use Blend to data bind with the tool's support. - /// - /// - /// See http://www.galasoft.ch/mvvm - /// /// - public class MainViewModel : ViewModelBase + public class MainViewModel : ObservableRecipient { private string informationMessage; private ObservableCollection conversionJobs; @@ -39,21 +30,11 @@ namespace FileConverter.ViewModels /// public MainViewModel() { - if (this.IsInDesignMode) - { - // Code runs in Blend --> create design time data. - this.InformationMessage = "Design time mode."; - this.ConversionJobs = new ObservableCollection(); - //this.ConversionJobs.Add(new ConversionJob()); - } - else - { - IConversionService settingsService = SimpleIoc.Default.GetInstance(); - this.ConversionJobs = new ObservableCollection(settingsService.ConversionJobs); + IConversionService settingsService = Ioc.Default.GetRequiredService(); + this.ConversionJobs = new ObservableCollection(settingsService.ConversionJobs); - Application application = Application.Current as Application; - application.OnApplicationTerminate += this.Application_OnApplicationTerminate; - } + Application application = Application.Current as Application; + application.OnApplicationTerminate += this.Application_OnApplicationTerminate; } public string InformationMessage @@ -62,7 +43,7 @@ namespace FileConverter.ViewModels private set { - this.Set(ref this.informationMessage, value); + this.SetProperty(ref this.informationMessage, value); } } @@ -72,7 +53,7 @@ namespace FileConverter.ViewModels private set { - this.Set(ref this.conversionJobs, value); + this.SetProperty(ref this.conversionJobs, value); foreach (var job in this.conversionJobs) { @@ -87,7 +68,7 @@ namespace FileConverter.ViewModels { if (this.showSettingsCommand == null) { - this.showSettingsCommand = new RelayCommand(() => SimpleIoc.Default.GetInstance().Show(Pages.Settings)); + this.showSettingsCommand = new RelayCommand(() => Ioc.Default.GetRequiredService().Show(Pages.Settings)); } return this.showSettingsCommand; @@ -100,7 +81,7 @@ namespace FileConverter.ViewModels { if (this.showDiagnosticsCommand == null) { - this.showDiagnosticsCommand = new RelayCommand(() => SimpleIoc.Default.GetInstance().Show(Pages.Diagnostics)); + this.showDiagnosticsCommand = new RelayCommand(() => Ioc.Default.GetRequiredService().Show(Pages.Diagnostics)); } return this.showDiagnosticsCommand; @@ -122,7 +103,7 @@ namespace FileConverter.ViewModels private void Close(CancelEventArgs args) { - INavigationService navigationService = SimpleIoc.Default.GetInstance(); + INavigationService navigationService = Ioc.Default.GetRequiredService(); navigationService.Close(Pages.Main, args != null); } @@ -133,7 +114,7 @@ namespace FileConverter.ViewModels return; } - this.RaisePropertyChanged(nameof(this.ConversionJobs)); + this.OnPropertyChanged(nameof(this.ConversionJobs)); } private void Application_OnApplicationTerminate(object sender, ApplicationTerminateArgs eventArgs) diff --git a/Application/FileConverter/ViewModels/PresetNode.cs b/Application/FileConverter/ViewModels/PresetNode.cs index 1ee5c55..cf8ebd1 100644 --- a/Application/FileConverter/ViewModels/PresetNode.cs +++ b/Application/FileConverter/ViewModels/PresetNode.cs @@ -1,12 +1,13 @@ // License: http://www.gnu.org/licenses/gpl.html GPL version 3. -using System.Collections.ObjectModel; -using System.ComponentModel; -using System.Linq; -using GalaSoft.MvvmLight; - namespace FileConverter.ViewModels { + using System.Collections.ObjectModel; + using System.ComponentModel; + using System.Linq; + + using CommunityToolkit.Mvvm.ComponentModel; + public abstract class AbstractTreeNode : ObservableObject, IDataErrorInfo { private PresetFolderNode parent; @@ -28,7 +29,7 @@ namespace FileConverter.ViewModels set { this.parent = value; - this.RaisePropertyChanged(); + this.OnPropertyChanged(); } } @@ -135,8 +136,8 @@ namespace FileConverter.ViewModels set { this.Preset.ShortName = value; - this.RaisePropertyChanged(); - this.RaisePropertyChanged(nameof(this.HasError)); + this.OnPropertyChanged(); + this.OnPropertyChanged(nameof(this.HasError)); } } @@ -147,7 +148,7 @@ namespace FileConverter.ViewModels set { this.Preset.OutputFileNameTemplate = value; - this.RaisePropertyChanged(); + this.OnPropertyChanged(); } } @@ -255,8 +256,8 @@ namespace FileConverter.ViewModels set { this.name = value; - this.RaisePropertyChanged(); - this.RaisePropertyChanged(nameof(this.HasError)); + this.OnPropertyChanged(); + this.OnPropertyChanged(nameof(this.HasError)); } } @@ -267,7 +268,7 @@ namespace FileConverter.ViewModels set { this.children = value; - this.RaisePropertyChanged(); + this.OnPropertyChanged(); } } diff --git a/Application/FileConverter/ViewModels/SettingsViewModel.cs b/Application/FileConverter/ViewModels/SettingsViewModel.cs index 7dbe7d2..6e616a6 100644 --- a/Application/FileConverter/ViewModels/SettingsViewModel.cs +++ b/Application/FileConverter/ViewModels/SettingsViewModel.cs @@ -9,34 +9,23 @@ namespace FileConverter.ViewModels using System.Diagnostics; using System.Globalization; using System.Linq; - using System.Windows; using System.Windows.Data; using System.Windows.Input; + using Microsoft.Win32; + + using CommunityToolkit.Mvvm.ComponentModel; + using CommunityToolkit.Mvvm.DependencyInjection; + using CommunityToolkit.Mvvm.Input; + using FileConverter.Annotations; using FileConverter.Services; using FileConverter.Views; - using GalaSoft.MvvmLight; - using GalaSoft.MvvmLight.Command; - using GalaSoft.MvvmLight.Ioc; - using GalaSoft.MvvmLight.Messaging; - - using Microsoft.Win32; - /// - /// This class contains properties that the main View can data bind to. - /// - /// Use the mvvminpc snippet to add bindable properties to this ViewModel. - /// - /// - /// You can also use Blend to data bind with the tool's support. - /// - /// - /// See http://www.galasoft.ch/mvvm - /// + /// This class contains properties that the settings View can data bind to. /// - public class SettingsViewModel : ViewModelBase, IDataErrorInfo + public class SettingsViewModel : ObservableRecipient, IDataErrorInfo { private InputExtensionCategory[] inputCategories; private PresetFolderNode presetsRootFolder; @@ -59,6 +48,9 @@ namespace FileConverter.ViewModels private ListCollectionView outputTypes; private CultureInfo[] supportedCultures; + public event Action OnPresetCreated; + public event Action OnFolderCreated; + /// /// Initializes a new instance of the SettingsViewModel class. /// @@ -75,42 +67,33 @@ namespace FileConverter.ViewModels this.saveCommand = new RelayCommand(this.SaveSettings, this.CanSaveSettings); this.closeCommand = new RelayCommand(this.CloseSettings); - if (this.IsInDesignMode) - { - // Code runs in Blend --> create design time data. - this.Settings = new Settings(); - this.Settings.ConversionPresets.Add(new ConversionPreset("Test", OutputType.Mp3)); - } - else - { - ISettingsService settingsService = SimpleIoc.Default.GetInstance(); - this.Settings = settingsService.Settings; + ISettingsService settingsService = Ioc.Default.GetRequiredService(); + this.Settings = settingsService.Settings; - List outputTypeViewModels = new List(); - outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Ogg)); - outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Mp3)); - outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Aac)); - outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Flac)); - outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Wav)); - outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Mkv)); - outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Mp4)); - outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Ogv)); - outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Webm)); - outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Avi)); - outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Png)); - outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Jpg)); - outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Webp)); - outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Ico)); - outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Gif)); - outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Pdf)); - this.outputTypes = new ListCollectionView(outputTypeViewModels); - this.outputTypes.GroupDescriptions.Add(new PropertyGroupDescription("Category")); + List outputTypeViewModels = new List(); + outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Ogg)); + outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Mp3)); + outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Aac)); + outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Flac)); + outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Wav)); + outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Mkv)); + outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Mp4)); + outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Ogv)); + outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Webm)); + outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Avi)); + outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Png)); + outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Jpg)); + outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Webp)); + outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Ico)); + outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Gif)); + outputTypeViewModels.Add(new OutputTypeViewModel(OutputType.Pdf)); + this.outputTypes = new ListCollectionView(outputTypeViewModels); + this.outputTypes.GroupDescriptions.Add(new PropertyGroupDescription("Category")); - this.SupportedCultures = Helpers.GetSupportedCultures().ToArray(); + this.SupportedCultures = Helpers.GetSupportedCultures().ToArray(); - this.InitializeCompatibleInputExtensions(); - this.InitializePresetFolders(); - } + this.InitializeCompatibleInputExtensions(); + this.InitializePresetFolders(); } public IEnumerable InputCategories @@ -147,7 +130,7 @@ namespace FileConverter.ViewModels set { this.presetsRootFolder = value; - this.RaisePropertyChanged(); + this.OnPropertyChanged(); } } @@ -181,7 +164,7 @@ namespace FileConverter.ViewModels this.SelectedFolder = null; } - this.RaisePropertyChanged(); + this.OnPropertyChanged(); } } @@ -193,11 +176,11 @@ namespace FileConverter.ViewModels { this.selectedFolder = value; - this.RaisePropertyChanged(); - this.RaisePropertyChanged(nameof(this.SelectedItem)); - this.removePresetCommand?.RaiseCanExecuteChanged(); - this.exportPresetCommand?.RaiseCanExecuteChanged(); - this.duplicatePresetCommand?.RaiseCanExecuteChanged(); + this.OnPropertyChanged(); + this.OnPropertyChanged(nameof(this.SelectedItem)); + this.removePresetCommand?.NotifyCanExecuteChanged(); + this.exportPresetCommand?.NotifyCanExecuteChanged(); + this.duplicatePresetCommand?.NotifyCanExecuteChanged(); } } @@ -219,12 +202,12 @@ namespace FileConverter.ViewModels this.selectedPreset.Preset.PropertyChanged += this.SelectedPresetPropertyChanged; } - this.RaisePropertyChanged(); - this.RaisePropertyChanged(nameof(this.SelectedItem)); - this.RaisePropertyChanged(nameof(this.InputCategories)); - this.removePresetCommand?.RaiseCanExecuteChanged(); - this.exportPresetCommand?.RaiseCanExecuteChanged(); - this.duplicatePresetCommand?.RaiseCanExecuteChanged(); + this.OnPropertyChanged(); + this.OnPropertyChanged(nameof(this.SelectedItem)); + this.OnPropertyChanged(nameof(this.InputCategories)); + this.removePresetCommand?.NotifyCanExecuteChanged(); + this.exportPresetCommand?.NotifyCanExecuteChanged(); + this.duplicatePresetCommand?.NotifyCanExecuteChanged(); } } @@ -235,7 +218,7 @@ namespace FileConverter.ViewModels set { this.settings = value; - this.RaisePropertyChanged(); + this.OnPropertyChanged(); } } @@ -245,7 +228,7 @@ namespace FileConverter.ViewModels set { this.supportedCultures = value; - this.RaisePropertyChanged(); + this.OnPropertyChanged(); } } @@ -255,7 +238,7 @@ namespace FileConverter.ViewModels set { this.outputTypes = value; - this.RaisePropertyChanged(); + this.OnPropertyChanged(); } } @@ -270,7 +253,7 @@ namespace FileConverter.ViewModels { this.displaySeeChangeLogLink = value; - this.RaisePropertyChanged(); + this.OnPropertyChanged(); } } @@ -375,20 +358,20 @@ namespace FileConverter.ViewModels { if (eventArgs.PropertyName == "OutputType") { - this.RaisePropertyChanged(nameof(this.InputCategories)); + this.OnPropertyChanged(nameof(this.InputCategories)); } - this.saveCommand.RaiseCanExecuteChanged(); + this.saveCommand.NotifyCanExecuteChanged(); } private void NodePropertyChanged(object sender, PropertyChangedEventArgs eventArgs) { - this.saveCommand.RaiseCanExecuteChanged(); + this.saveCommand.NotifyCanExecuteChanged(); } private void DownloadChangeLogAction() { - IUpgradeService upgradeService = SimpleIoc.Default.GetInstance(); + IUpgradeService upgradeService = Ioc.Default.GetRequiredService(); upgradeService.DownloadChangeLog(); this.DisplaySeeChangeLogLink = false; } @@ -411,7 +394,7 @@ namespace FileConverter.ViewModels } this.inputCategories = categories.ToArray(); - this.RaisePropertyChanged(nameof(this.InputCategories)); + this.OnPropertyChanged(nameof(this.InputCategories)); } private void InitializePresetFolders() @@ -434,7 +417,7 @@ namespace FileConverter.ViewModels this.CreatePresetNode(preset, parent); } - this.RaisePropertyChanged(nameof(this.PresetsRootFolder)); + this.OnPropertyChanged(nameof(this.PresetsRootFolder)); } private void ComputePresetsParentFoldersNamesAndFillSettings(AbstractTreeNode node, List folderNamesCache) @@ -465,10 +448,10 @@ namespace FileConverter.ViewModels private void CloseSettings(CancelEventArgs args) { - ISettingsService settingsService = SimpleIoc.Default.GetInstance(); + ISettingsService settingsService = Ioc.Default.GetRequiredService(); settingsService.RevertSettings(); - INavigationService navigationService = SimpleIoc.Default.GetInstance(); + INavigationService navigationService = Ioc.Default.GetRequiredService(); navigationService.Close(Pages.Settings, args != null); } @@ -484,10 +467,10 @@ namespace FileConverter.ViewModels this.ComputePresetsParentFoldersNamesAndFillSettings(this.presetsRootFolder, new List()); // Save changes. - ISettingsService settingsService = SimpleIoc.Default.GetInstance(); + ISettingsService settingsService = Ioc.Default.GetRequiredService(); settingsService.SaveSettings(); - INavigationService navigationService = SimpleIoc.Default.GetInstance(); + INavigationService navigationService = Ioc.Default.GetRequiredService(); navigationService.Close(Pages.Settings, false); } @@ -530,9 +513,9 @@ namespace FileConverter.ViewModels this.SelectedItem = newFolder; - this.saveCommand.RaiseCanExecuteChanged(); + this.saveCommand.NotifyCanExecuteChanged(); - Messenger.Default.Send("FolderName", "DoFocus"); + this.OnFolderCreated(); } private bool CanDuplicateSelectedPreset() @@ -590,10 +573,10 @@ namespace FileConverter.ViewModels this.SelectedItem = node; - Messenger.Default.Send("PresetName", "DoFocus"); + this.OnPresetCreated.Invoke(); - this.removePresetCommand.RaiseCanExecuteChanged(); - this.saveCommand.RaiseCanExecuteChanged(); + this.removePresetCommand.NotifyCanExecuteChanged(); + this.saveCommand.NotifyCanExecuteChanged(); } private void ImportPreset() @@ -699,8 +682,8 @@ namespace FileConverter.ViewModels this.SelectedItem = null; - this.removePresetCommand.RaiseCanExecuteChanged(); - this.saveCommand.RaiseCanExecuteChanged(); + this.removePresetCommand.NotifyCanExecuteChanged(); + this.saveCommand.NotifyCanExecuteChanged(); } private bool CanRemoveSelectedPreset() @@ -708,9 +691,9 @@ namespace FileConverter.ViewModels return this.SelectedItem != null; } - public override void Cleanup() + protected override void OnDeactivated() { - base.Cleanup(); + base.OnDeactivated(); this.UnbindNode(this.presetsRootFolder); } diff --git a/Application/FileConverter/ViewModels/UpgradeViewModel.cs b/Application/FileConverter/ViewModels/UpgradeViewModel.cs index 2250525..2a9c00c 100644 --- a/Application/FileConverter/ViewModels/UpgradeViewModel.cs +++ b/Application/FileConverter/ViewModels/UpgradeViewModel.cs @@ -5,25 +5,16 @@ namespace FileConverter.ViewModels using System.ComponentModel; using System.Windows.Input; + using CommunityToolkit.Mvvm.ComponentModel; + using CommunityToolkit.Mvvm.DependencyInjection; + using CommunityToolkit.Mvvm.Input; + using FileConverter.Services; - using GalaSoft.MvvmLight; - using GalaSoft.MvvmLight.Command; - using GalaSoft.MvvmLight.Ioc; - /// - /// This class contains properties that the main View can data bind to. - /// - /// Use the mvvminpc snippet to add bindable properties to this ViewModel. - /// - /// - /// You can also use Blend to data bind with the tool's support. - /// - /// - /// See http://www.galasoft.ch/mvvm - /// + /// This class contains properties that the upgrade View can data bind to. /// - public class UpgradeViewModel : ViewModelBase + public class UpgradeViewModel : ObservableRecipient { private readonly IUpgradeService upgradeService; @@ -36,7 +27,7 @@ namespace FileConverter.ViewModels /// public UpgradeViewModel() { - this.upgradeService = SimpleIoc.Default.GetInstance(); + this.upgradeService = Ioc.Default.GetRequiredService(); this.upgradeService.DownloadChangeLog(); } @@ -83,19 +74,19 @@ namespace FileConverter.ViewModels { this.upgradeService.StartUpgrade(); - INavigationService navigationService = SimpleIoc.Default.GetInstance(); + INavigationService navigationService = Ioc.Default.GetRequiredService(); navigationService.Close(Pages.Upgrade, false); } private void ExecuteLaunchInstallerCommand() { - INavigationService navigationService = SimpleIoc.Default.GetInstance(); + INavigationService navigationService = Ioc.Default.GetRequiredService(); navigationService.Close(Pages.Upgrade, false); } private void Close(CancelEventArgs args) { - INavigationService navigationService = SimpleIoc.Default.GetInstance(); + INavigationService navigationService = Ioc.Default.GetRequiredService(); navigationService.Close(Pages.Upgrade, args != null); } } diff --git a/Application/FileConverter/ViewModels/ViewModelLocator.cs b/Application/FileConverter/ViewModels/ViewModelLocator.cs index e816418..24e2430 100644 --- a/Application/FileConverter/ViewModels/ViewModelLocator.cs +++ b/Application/FileConverter/ViewModels/ViewModelLocator.cs @@ -9,21 +9,12 @@ In the View: DataContext="{Binding Source={StaticResource Locator}, Path=ViewModelName}" - - You can also use Blend to do all this with the tool's support. - See http://www.galasoft.ch/mvvm */ namespace FileConverter.ViewModels { - using System; - - using CommonServiceLocator; - - using FileConverter.Views; - - using GalaSoft.MvvmLight.Ioc; - using GalaSoft.MvvmLight.Views; + using CommunityToolkit.Mvvm.DependencyInjection; + using Microsoft.Extensions.DependencyInjection; /// /// This class contains static references to all the view models in the @@ -36,34 +27,26 @@ namespace FileConverter.ViewModels /// public ViewModelLocator() { - ServiceLocator.SetLocatorProvider(() => SimpleIoc.Default); - - ////if (ViewModelBase.IsInDesignModeStatic) - ////{ - //// // Create design time view services and models - //// SimpleIoc.Default.Register(); - ////} - ////else - ////{ - //// // Create run time view services and models - //// SimpleIoc.Default.Register(); - ////} - - SimpleIoc.Default.Register(); - SimpleIoc.Default.Register(); - SimpleIoc.Default.Register(); - SimpleIoc.Default.Register(); - SimpleIoc.Default.Register(); } - public HelpViewModel Help => ServiceLocator.Current.GetInstance(); + public HelpViewModel Help => Ioc.Default.GetRequiredService(); - public MainViewModel Main => ServiceLocator.Current.GetInstance(); + public MainViewModel Main => Ioc.Default.GetRequiredService(); - public UpgradeViewModel Upgrade => ServiceLocator.Current.GetInstance(); + public UpgradeViewModel Upgrade => Ioc.Default.GetRequiredService(); - public SettingsViewModel Settings => ServiceLocator.Current.GetInstance(); + public SettingsViewModel Settings => Ioc.Default.GetRequiredService(); - public DiagnosticsViewModel Diagnostics => ServiceLocator.Current.GetInstance(); + public DiagnosticsViewModel Diagnostics => Ioc.Default.GetRequiredService(); + + internal void RegisterViewModels(ServiceCollection services) + { + services + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton() + .AddSingleton(); + } } } \ No newline at end of file diff --git a/Application/FileConverter/Views/BindableSelectedItemBehavior.cs b/Application/FileConverter/Views/BindableSelectedItemBehavior.cs index 8204034..b1ccc2f 100644 --- a/Application/FileConverter/Views/BindableSelectedItemBehavior.cs +++ b/Application/FileConverter/Views/BindableSelectedItemBehavior.cs @@ -3,7 +3,7 @@ using System.Collections.Specialized; using System.Windows; using System.Windows.Controls; -using System.Windows.Interactivity; +using Microsoft.Xaml.Behaviors; namespace FileConverter.Views { diff --git a/Application/FileConverter/Views/DiagnosticsWindow.xaml b/Application/FileConverter/Views/DiagnosticsWindow.xaml index c6aad8b..d0eb5eb 100644 --- a/Application/FileConverter/Views/DiagnosticsWindow.xaml +++ b/Application/FileConverter/Views/DiagnosticsWindow.xaml @@ -6,16 +6,15 @@ xmlns:diagnostics="clr-namespace:FileConverter.Diagnostics" xmlns:project="clr-namespace:FileConverter.Properties" xmlns:local="clr-namespace:FileConverter" - xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" - xmlns:command="http://www.galasoft.ch/mvvmlight" + xmlns:behaviors="http://schemas.microsoft.com/xaml/behaviors" mc:Ignorable="d" Height="600" Width="800" Icon="/FileConverter;component/Resources/ApplicationIcon.ico" DataContext="{Binding Diagnostics, Source={StaticResource Locator}}"> - - - - - + + + + + diff --git a/Application/FileConverter/Views/HelpWindow.xaml b/Application/FileConverter/Views/HelpWindow.xaml index 033ba66..368ceaa 100644 --- a/Application/FileConverter/Views/HelpWindow.xaml +++ b/Application/FileConverter/Views/HelpWindow.xaml @@ -6,16 +6,15 @@ xmlns:fileConverter="clr-namespace:FileConverter" xmlns:project="clr-namespace:FileConverter.Properties" xmlns:gif="http://wpfanimatedgif.codeplex.com" - xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" - xmlns:command="http://www.galasoft.ch/mvvmlight" + xmlns:behaviors="http://schemas.microsoft.com/xaml/behaviors" mc:Ignorable="d" Icon="/FileConverter;component/Resources/ApplicationIcon.ico" WindowStartupLocation="CenterScreen" WindowStyle="ToolWindow" ResizeMode="NoResize" Width="640" Height="545" DataContext="{Binding Help, Source={StaticResource Locator}}"> - - - - - + + + + + diff --git a/Application/FileConverter/Views/MainWindow.xaml b/Application/FileConverter/Views/MainWindow.xaml index 3f8e6d7..51704f1 100644 --- a/Application/FileConverter/Views/MainWindow.xaml +++ b/Application/FileConverter/Views/MainWindow.xaml @@ -6,16 +6,15 @@ xmlns:valueConverters="clr-namespace:FileConverter.ValueConverters" xmlns:project="clr-namespace:FileConverter.Properties" xmlns:controls="clr-namespace:FileConverter.Controls" - xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" - xmlns:command="http://www.galasoft.ch/mvvmlight" + xmlns:behaviors="http://schemas.microsoft.com/xaml/behaviors" mc:Ignorable="d" x:Class="FileConverter.Views.MainWindow" Height="500" Width="950" MinHeight="480" MinWidth="640" WindowStartupLocation="CenterScreen" Icon="/FileConverter;component/Resources/ApplicationIcon.ico" DataContext="{Binding Main, Source={StaticResource Locator}}"> - - - - - + + + + + diff --git a/Application/FileConverter/Views/SettingsWindow.xaml b/Application/FileConverter/Views/SettingsWindow.xaml index 475745d..58941e0 100644 --- a/Application/FileConverter/Views/SettingsWindow.xaml +++ b/Application/FileConverter/Views/SettingsWindow.xaml @@ -6,8 +6,7 @@ xmlns:project="clr-namespace:FileConverter.Properties" xmlns:views="clr-namespace:FileConverter.Views" xmlns:viewModels="clr-namespace:FileConverter.ViewModels" - xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" - xmlns:command="http://www.galasoft.ch/mvvmlight" + xmlns:behaviors="http://schemas.microsoft.com/xaml/behaviors" xmlns:generic="clr-namespace:FileConverter.ValueConverters.Generic" xmlns:controls="clr-namespace:FileConverter.Controls" x:Class="FileConverter.Views.SettingsWindow" @@ -17,11 +16,11 @@ mc:Ignorable="d" DataContext="{Binding Settings, Source={StaticResource Locator}}" d:DataContext="{d:DesignData /SampleData/SettingsSampleData.xaml}"> - - - - - + + + + + @@ -292,12 +291,12 @@ - + - + diff --git a/Application/FileConverter/Views/SettingsWindow.xaml.cs b/Application/FileConverter/Views/SettingsWindow.xaml.cs index 4b3725a..1385b26 100644 --- a/Application/FileConverter/Views/SettingsWindow.xaml.cs +++ b/Application/FileConverter/Views/SettingsWindow.xaml.cs @@ -2,8 +2,7 @@ namespace FileConverter.Views { - using System; - using System.Linq; + using System.ComponentModel; using System.Windows; using System.Windows.Controls; using System.Windows.Input; @@ -12,8 +11,6 @@ namespace FileConverter.Views using FileConverter.Diagnostics; using FileConverter.ViewModels; - using GalaSoft.MvvmLight.Messaging; - /// /// Interaction logic for Settings. /// @@ -35,14 +32,30 @@ namespace FileConverter.Views { this.InitializeComponent(); - Messenger.Default.Register(this, "DoFocus", this.DoFocus); + SettingsViewModel settingsViewModel = this.DataContext as SettingsViewModel; + settingsViewModel.OnPresetCreated += this.SettingsWindow_OnPresetCreated; + settingsViewModel.OnFolderCreated += this.SettingsWindow_OnFolderCreated; - (this.DataContext as SettingsViewModel).PropertyChanged += this.SettingsWindow_PropertyChanged; + settingsViewModel.PropertyChanged += this.SettingsWindow_PropertyChanged; this.PresetTreeView.MouseDown += this.TreeView_MouseDown; this.PresetTreeView.MouseUp += this.TreeView_MouseUp; } + private void SettingsWindow_OnPresetCreated() + { + this.focusMessage = "PresetName"; + this.selectedPresetNameTextBox?.Focus(); + this.selectedPresetNameTextBox?.SelectAll(); + } + + private void SettingsWindow_OnFolderCreated() + { + this.focusMessage = "FolderName"; + this.selectedFolderNameTextBox?.Focus(); + this.selectedFolderNameTextBox?.SelectAll(); + } + private void SettingsWindow_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs args) { if (args.PropertyName == "SelectedItem") @@ -52,23 +65,6 @@ namespace FileConverter.Views } } - public void DoFocus(string message) - { - this.focusMessage = message; - switch (message) - { - case "PresetName": - this.selectedPresetNameTextBox?.Focus(); - this.selectedPresetNameTextBox?.SelectAll(); - break; - - case "FolderName": - this.selectedFolderNameTextBox?.Focus(); - this.selectedFolderNameTextBox?.SelectAll(); - break; - } - } - private void TreeView_MouseDown(object sender, MouseButtonEventArgs args) { FrameworkElement element = args.OriginalSource as FrameworkElement; @@ -345,7 +341,7 @@ namespace FileConverter.Views this.selectedPresetNameTextBox = (TextBox)sender; if (this.focusMessage == "PresetName") { - this.DoFocus(this.focusMessage); + this.selectedPresetNameTextBox.Focus(); this.focusMessage = null; } } @@ -355,7 +351,7 @@ namespace FileConverter.Views this.selectedFolderNameTextBox = (TextBox)sender; if (this.focusMessage == "FolderName") { - this.DoFocus(this.focusMessage); + this.selectedFolderNameTextBox.Focus(); this.focusMessage = null; } } diff --git a/Application/FileConverter/Views/UpgradeWindow.xaml b/Application/FileConverter/Views/UpgradeWindow.xaml index f3ee4b4..8f49145 100644 --- a/Application/FileConverter/Views/UpgradeWindow.xaml +++ b/Application/FileConverter/Views/UpgradeWindow.xaml @@ -4,19 +4,18 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:project="clr-namespace:FileConverter.Properties" - xmlns:i="http://schemas.microsoft.com/expression/2010/interactivity" - xmlns:command="http://www.galasoft.ch/mvvmlight" + xmlns:behaviors="http://schemas.microsoft.com/xaml/behaviors" mc:Ignorable="d" Title="{x:Static project:Resources.UpgradeWindowTitle}" WindowStartupLocation="CenterScreen" Icon="/FileConverter;component/Resources/ApplicationIcon.ico" MinHeight="300" MinWidth="450" Height="450" Width="450" WindowStyle="ToolWindow" DataContext="{Binding Upgrade, Source={StaticResource Locator}}"> - - - - - + + + + + diff --git a/Application/FileConverter/XmlHelpers.cs b/Application/FileConverter/XmlHelpers.cs index e06e79f..9233c71 100644 --- a/Application/FileConverter/XmlHelpers.cs +++ b/Application/FileConverter/XmlHelpers.cs @@ -2,12 +2,6 @@ namespace FileConverter { - using System; - using System.Collections.Generic; - using System.IO; - using System.Xml; - using System.Xml.Serialization; - public class XmlHelpers { public static void LoadFromFile(string root, string path, out T deserializedObject) diff --git a/Application/FileConverter/packages.config b/Application/FileConverter/packages.config index 1275753..dd2d9fb 100644 --- a/Application/FileConverter/packages.config +++ b/Application/FileConverter/packages.config @@ -1,14 +1,22 @@  - + + + + - - + + + + + + + \ No newline at end of file diff --git a/Installer/Product.wxs b/Installer/Product.wxs index 200b0ef..8197c00 100644 --- a/Installer/Product.wxs +++ b/Installer/Product.wxs @@ -84,22 +84,6 @@ - - - - - - - - - - - - - - - -