Reload itemsource d'un datagrid wpf MVVM
Bonjour à tous,
je ne sais pas si je suis au bon endroit.
voilà mon problème je développe une application C# WPF en MVVM
j'ai un datagrid et un bouton de synchronisation. j'arrive bien à synchroner mais pas à dire à mon model de mettre à jour le datagrid.
voici mon code : WPF (xaml)
Code:
1 2 3 4 5
| <DataGrid IsReadOnly="true" x:Name="Dt_ListeApplicationARV">
<Button Name="btn_synchro"
Style="{StaticResource MaterialDesignFloatingActionLightButton}"
Command="{Binding SynchroCommand}"> |
code behind
Code:
1 2 3 4 5 6 7 8 9 10 11
| public partial class ListeLogiciels : Window
{
public ListeLogiciels()
{
InitializeComponent();
DataContext = new ListeLogicielsViewModel();
var applis = new ListeLogicielsViewModel();
Dt_ListeApplicationARV.ItemsSource = applis.LoadApplications();
} |
Mon fichier ViewModel
c'est dans ce fichier que s'exécute le Command de bon bouton, mais impossible de lui dire de réinitialiser l'itemsource.
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51
| public class ListeLogicielsViewModel : ViewModelBase
{
private AVSContext _context = new AVSContext();
}
public ListeLogicielsViewModel()
{
var Dt_ListeApplicationARV = this.LoadApplications();
SynchroCommand = new AnotherCommandImplementation(_ => DispatcheFunctionTime());
}
public void DispatcheFunctionTime()
{
if (IsSaveComplete == true)
{
IsSaveComplete = false;
return;
}
if (SaveProgress != 0) return;
var started = DateTime.Now;
IsSaving = true;
Actions toDo = new Actions();
Todo.Synchronisation();
new DispatcherTimer(
TimeSpan.FromMilliseconds(50),
DispatcherPriority.Normal,
new EventHandler((o, e) =>
{
var totalDuration = started.AddSeconds(3).Ticks - started.Ticks;
var currentProgress = DateTime.Now.Ticks - started.Ticks;
var currentProgressPercent = 100.0 / totalDuration * currentProgress;
SaveProgress = currentProgressPercent;
if (SaveProgress >= 100)
{
IsSaveComplete = true;
IsSaving = false;
SaveProgress = 0;
if (o is DispatcherTimer timer)
{
timer.Stop();
}
}
}), Dispatcher.CurrentDispatcher);
} |
merci d'avance pour votre aide.