MvvmScarletToolkit icon indicating copy to clipboard operation
MvvmScarletToolkit copied to clipboard

UWP Support: Add ScarletCommandManager that doesnt rely on WPFs CommandManager

Open mastorm opened this issue 5 years ago • 2 comments

Microsoft removed the CommandManager in UWP.

https://github.com/Insire/MvvmScarletToolkit/blob/216c0b93361f94f344268fd5f084fbcb4d466086/src/MvvmScarletToolkit.Implementations/ScarletCommandManager.cs#L10

The current implementation relies on CommandManager. The fix is pretty easy, since you already abstracted it away behind an IScarletCommandManager

Something like this COULD do the job(needs re-evaluation by somebody more experienced than me):

        public sealed class UwpScarletCommandManager : IScarletCommandManager
        {
            private static readonly Lazy<UwpScarletCommandManager > _default = new Lazy<ScarletCommandManager>(() => new UwpScarletCommandManager ());

            public static IScarletCommandManager Default { get; } = _default.Value;

            public event EventHandler RequerySuggested { get; set; }

            public void InvalidateRequerySuggested()
            {
                CanExecuteChanged?.Invoke(this, EventArgs.Empty);
            }
        }

This solution is basically from this stackoverflow thread: https://stackoverflow.com/questions/12030697/what-replaces-commandmanager-in-winrt

mastorm avatar Jan 29 '20 20:01 mastorm

I've come up with this based on your link and little of my own googling. Gonna test it somewhen and add it to the repo after that.

    public sealed class UwpScarletCommandManager : IScarletCommandManager
    {
        private static readonly Lazy<UwpScarletCommandManager> _default = new Lazy<UwpScarletCommandManager>(() => new UwpScarletCommandManager());

        public static IScarletCommandManager Default { get; } = _default.Value;

        public event EventHandler? RequerySuggested;

        public void InvalidateRequerySuggested()
        {
            RequerySuggested?.Invoke(this, EventArgs.Empty);
        }
    }

Insire avatar Jan 29 '20 20:01 Insire

Will test this in my app too, gonna add it here if i notice a rough edge or something

mastorm avatar Jan 29 '20 20:01 mastorm