mirror of
https://github.com/Nioux/AideDeJeu.git
synced 2025-10-30 15:06:06 +00:00
Réparation provisoir UWP
This commit is contained in:
parent
48a5a94371
commit
c1c00d0659
3 changed files with 30 additions and 13 deletions
|
|
@ -19,7 +19,7 @@ namespace AideDeJeu.ViewModels
|
|||
public ItemsViewModel(ItemSourceType itemSourceType)
|
||||
{
|
||||
this.ItemSourceType = itemSourceType;
|
||||
LoadItemsCommand = new Command(async () => await ExecuteLoadItemsCommandAsync());
|
||||
LoadItemsCommand = new Command(async () => await ExecuteLoadItemsCommandAsync().ConfigureAwait(false));
|
||||
}
|
||||
public ICommand LoadItemsCommand { get; protected set; }
|
||||
//public abstract void ExecuteLoadItemsCommand();
|
||||
|
|
@ -75,19 +75,24 @@ namespace AideDeJeu.ViewModels
|
|||
Main.IsLoading = true;
|
||||
try
|
||||
{
|
||||
// Yan : c'est pas plutôt cette partie qui devrait être dans une autre Task ?
|
||||
var filterViewModel = Main.GetFilterViewModel(ItemSourceType);
|
||||
var items = await filterViewModel.FilterItems(AllItems, token);
|
||||
await Task.Run(() =>
|
||||
{
|
||||
Main.Items.Clear();
|
||||
foreach (var item in items)
|
||||
{
|
||||
token.ThrowIfCancellationRequested();
|
||||
Main.Items.Add(item);
|
||||
}
|
||||
});
|
||||
|
||||
await Task.Run(async () => {
|
||||
// Yan : plus besoin de boucle si on change toute la liste d'un coup ;)
|
||||
// Yan : indispensable de repasser sur l'ui thread pour la version uwp
|
||||
Device.BeginInvokeOnMainThread(() => Main.Items = items);
|
||||
//Main.Items.Clear();
|
||||
//foreach (var item in items)
|
||||
//{
|
||||
// token.ThrowIfCancellationRequested();
|
||||
// Main.Items.Add(item);
|
||||
//}
|
||||
}, cancellationToken: token); // Yan : c'est ici qu'il faudrait coller le token non ?
|
||||
|
||||
//On arrete le loading ici car on annule toujours avant de lancer une nouvelle opération
|
||||
// Yan : ?? du coup le IsLoading repasse pas à false en cas de cancel ou d'autre exception ?
|
||||
Main.IsLoading = false;
|
||||
}
|
||||
catch (OperationCanceledException ex)
|
||||
|
|
|
|||
|
|
@ -89,7 +89,19 @@ namespace AideDeJeu.ViewModels
|
|||
return AllFiltersViewModel[itemSourceType].Value;
|
||||
}
|
||||
|
||||
public ObservableCollection<Item> Items { get; private set; } = new ObservableCollection<Item>();
|
||||
// Yan : pas besoin d'ObservableCollection, on ne modifie jamais la liste item par item
|
||||
public IEnumerable<Item> _Items = new List<Item>();
|
||||
public IEnumerable<Item> Items
|
||||
{
|
||||
get
|
||||
{
|
||||
return _Items;
|
||||
}
|
||||
set
|
||||
{
|
||||
SetProperty(ref _Items, value);
|
||||
}
|
||||
}
|
||||
|
||||
private Item _SelectedItem;
|
||||
public Item SelectedItem
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@
|
|||
using AideDeJeuLib.Monsters;
|
||||
using AideDeJeuLib.Spells;
|
||||
using System;
|
||||
|
||||
using System.Linq;
|
||||
using Xamarin.Forms;
|
||||
using Xamarin.Forms.Xaml;
|
||||
|
||||
|
|
@ -35,7 +35,7 @@ namespace AideDeJeu.Views
|
|||
{
|
||||
base.OnAppearing();
|
||||
|
||||
if (Main.Items.Count == 0)
|
||||
if (Main.Items.Count() == 0)
|
||||
Main.LoadItemsCommand.Execute(null);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue