diff --git a/Properties/AssemblyInfo.cs b/Properties/AssemblyInfo.cs index 939614d..a65e74f 100644 --- a/Properties/AssemblyInfo.cs +++ b/Properties/AssemblyInfo.cs @@ -27,7 +27,7 @@ using System.Runtime.InteropServices; [assembly: AssemblyProduct("Nuclex.Avalonia")] [assembly: AssemblyDescription("Lean and elegant MVVM library with extras for Avalonia")] [assembly: AssemblyCompany("Nuclex Development Labs")] -[assembly: AssemblyCopyright("Copyright © Markus Ewald / Nuclex Development Labs 2002-2025")] +[assembly: AssemblyCopyright("Copyright © Markus Ewald / Nuclex Development Labs 2002-2026")] [assembly: AssemblyTrademark("")] [assembly: AssemblyCulture("")] @@ -46,4 +46,4 @@ using System.Runtime.InteropServices; // Build Number // Revision // -[assembly: AssemblyVersion("1.4.0")] +[assembly: AssemblyVersion("1.5.0")] diff --git a/Source/ViewModels/IMultiPageViewModel.cs b/Source/ViewModels/IMultiPageViewModel.cs index ab0dabe..d9cf760 100644 --- a/Source/ViewModels/IMultiPageViewModel.cs +++ b/Source/ViewModels/IMultiPageViewModel.cs @@ -24,8 +24,11 @@ using Nuclex.Avalonia.Commands; namespace Nuclex.Avalonia.ViewModels { /// Interface for view models that can switch between different pages - /// Enum type by which pages can be indicated - public interface IMultiPageViewModel { + /// + /// Type by which pages can be indicated (typically an enum) + /// + public interface IMultiPageViewModel + where TPageEnumeration : struct { /// Command to switch the active tool page IAsyncCommand SwitchPageCommand { get; } diff --git a/Source/ViewModels/MultiPageViewModel.cs b/Source/ViewModels/MultiPageViewModel.cs index 4f4957b..b46a12f 100644 --- a/Source/ViewModels/MultiPageViewModel.cs +++ b/Source/ViewModels/MultiPageViewModel.cs @@ -18,6 +18,7 @@ limitations under the License. #endregion // Apache License 2.0 using System; +using System.Collections; using System.Collections.Concurrent; using System.Threading.Tasks; @@ -27,9 +28,12 @@ using Nuclex.Support; namespace Nuclex.Avalonia.ViewModels { /// Base class for view models that have multiple child view models - /// Enum type by which pages can be indicated + /// + /// Type by which pages can be indicated (typically an enum) + /// public abstract class MultiPageViewModel : - Observable, IMultiPageViewModel, IDisposable { + Observable, IMultiPageViewModel, IDisposable + where TPageEnumeration : struct { /// Initializes a new multi-page view model /// @@ -98,8 +102,8 @@ namespace Nuclex.Avalonia.ViewModels { /// Switches to another page /// New page to switch to /// A task that will finish when the new page has been switched to - private Task switchPageAsync(TPageEnumeration? newPage) { - if(newPage.Equals(this.activePage)) { + private Task switchPageAsync(TPageEnumeration newPage) { + if(Comparer.Default.Compare(this.activePage, newPage) == 0) { return Task.CompletedTask; } @@ -116,7 +120,7 @@ namespace Nuclex.Avalonia.ViewModels { // Double-checked locking to avoid creating a view model for the same page // multiple times if the construction takes time - object newPageViewModel; + object? newPageViewModel; if(!this.cachedViewModels.TryGetValue(newPage, out newPageViewModel)) { lock(this.cachedViewModels) { if(!this.cachedViewModels.TryGetValue(newPage, out newPageViewModel)) { @@ -155,7 +159,7 @@ namespace Nuclex.Avalonia.ViewModels { private readonly ConcurrentDictionary? cachedViewModels; /// Page that is currently active in the multi-page view model - private TPageEnumeration activePage; + private TPageEnumeration? activePage; /// View model for the active page private object? activePageViewModel;