Fix CanGenerate

This commit is contained in:
2019-03-13 00:59:40 +01:00
parent 1996d0fe09
commit 52f7f336c8
2 changed files with 10 additions and 10 deletions

View File

@@ -6,10 +6,13 @@ namespace LaDOSE.DesktopApp.Utils
{
public static class WpfUtil
{
public static void AddUI<T>(this ICollection<T> collection, T item)
public static void AddUI<T>(this ICollection<T> collection, T item, Action action = null)
{
Action<T> addMethod = collection.Add;
Application.Current.Dispatcher.BeginInvoke(addMethod, item);
}
if(action!=null)
Application.Current.Dispatcher.BeginInvoke(action);
}
}
}

View File

@@ -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);
}
}