From 52f7f336c83cc8683b2e52843f21707b044a6173 Mon Sep 17 00:00:00 2001 From: Darkstack <1835601+darkstack@users.noreply.github.com> Date: Wed, 13 Mar 2019 00:59:40 +0100 Subject: [PATCH] Fix CanGenerate --- LaDOSE.Src/LaDOSE.DesktopApp/Utils/WpfUtil.cs | 5 ++++- .../ViewModels/WordPressViewModel.cs | 15 ++++++--------- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/Utils/WpfUtil.cs b/LaDOSE.Src/LaDOSE.DesktopApp/Utils/WpfUtil.cs index 40323fc..536810f 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/Utils/WpfUtil.cs +++ b/LaDOSE.Src/LaDOSE.DesktopApp/Utils/WpfUtil.cs @@ -6,10 +6,13 @@ namespace LaDOSE.DesktopApp.Utils { public static class WpfUtil { - public static void AddUI(this ICollection collection, T item) + public static void AddUI(this ICollection collection, T item, Action action = null) { Action addMethod = collection.Add; Application.Current.Dispatcher.BeginInvoke(addMethod, item); + if(action!=null) + Application.Current.Dispatcher.BeginInvoke(action); } + } } \ No newline at end of file diff --git a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WordPressViewModel.cs b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WordPressViewModel.cs index 856b346..75949c8 100644 --- a/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WordPressViewModel.cs +++ b/LaDOSE.Src/LaDOSE.DesktopApp/ViewModels/WordPressViewModel.cs @@ -72,13 +72,14 @@ namespace LaDOSE.DesktopApp.ViewModels Players.Clear(); PlayersOptions.Clear(); - Task.Factory.StartNew(LoadPlayers, TaskCreationOptions.LongRunning).ContinueWith(t => { }, - CancellationToken.None, TaskContinuationOptions.OnlyOnFaulted, + Task.Factory.StartNew(LoadPlayers, TaskCreationOptions.LongRunning).ContinueWith( + t => { NotifyOfPropertyChange(() => this.CanGenerate); }, + CancellationToken.None, TaskContinuationOptions.OnlyOnRanToCompletion, TaskScheduler.FromCurrentSynchronizationContext()); NotifyOfPropertyChange(() => SelectedGame); - NotifyOfPropertyChange(() => this.CanGenerate); NotifyOfPropertyChange(() => Players); NotifyOfPropertyChange(() => PlayersOptions); + NotifyOfPropertyChange(() => this.CanGenerate); } } @@ -196,13 +197,9 @@ namespace LaDOSE.DesktopApp.ViewModels var findUser = FindUser(SelectedWpEvent.Id, SelectedGame); var findUser2 = FindUser(SelectedWpEvent.Id, SelectedGame,true); - findUser.ForEach((e) => this.Players.AddUI(e)); + findUser.ForEach((e) => this.Players.AddUI(e,()=>NotifyOfPropertyChange(() => this.CanGenerate))); findUser2.ForEach((e) => this.PlayersOptions.AddUI(e)); - //this.RestService.GetUsers(SelectedWpEvent.Id, SelectedGame.Id) - // .ForEach((e) => this.Players.AddUI(e)); - //this.RestService.GetUsersOptions(SelectedWpEvent.Id, SelectedGame.Id) - // .ForEach((e) => this.PlayersOptions.AddUI(e)); - NotifyOfPropertyChange(() => this.CanGenerate); + } }