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 behind
Code XAML : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5 <DataGrid IsReadOnly="true" x:Name="Dt_ListeApplicationARV"> <Button Name="btn_synchro" Style="{StaticResource MaterialDesignFloatingActionLightButton}" Command="{Binding SynchroCommand}">
Mon fichier ViewModel
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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(); }
c'est dans ce fichier que s'exécute le Command de bon bouton, mais impossible de lui dire de réinitialiser l'itemsource.
merci d'avance pour votre aide.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
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); }
Partager