Note that there are some explanatory texts on larger screens.

plurals
  1. POexecute a function in a viewmodel and real time refresh of the view
    text
    copied!<p>I have a small problem with my MVVM application.</p> <p>I have a function in a viewmodel which modify a collection. This collection is bind to the view to show a datagrid. When an user click on a button, the function modify the collection but it can take few minutes and the view is not refresh.</p> <p>My question is how can I execute this function to have the view refreshed in real time ?</p> <p>In another program I have used the dispatcher but it was in the code behind of the view without binding.</p> <p>Thanks</p> <p>Edit :</p> <p>Model :</p> <pre><code>public class Composants : INotifyPropertyChanged { private string _nom; public string Nom { get { return _nom; } set { _nom = value; OnPropertyChanged("Nom"); } } } </code></pre> <p>ViewModel :</p> <pre><code>public class PageSynchroViewModel : INotifyPropertyChanged { public void SynchroniserComposants() { foreach (var comp in _selectedVersion.ListeComposants) { comp.Nom = ""; } } </code></pre> <p>View (I don't put all the code):</p> <pre><code>&lt;Page x:Class="Centre_de_synchronisation.Vues.PageSynchro" [...] xmlns:app="clr-namespace:Centre_de_synchronisation.Classes" mc:Ignorable="d" d:DesignHeight="531" d:DesignWidth="778" Title="PageSynchro" Background="{x:Null}"&gt; &lt;Canvas&gt; [...] &lt;DataGrid Name="GridComposants" Style="{StaticResource DatagridStyle}" ItemsSource="{Binding ListeComposants}" AutoGenerateColumns="False" Canvas.Left="12" Canvas.Top="201" Height="285" Width="754" &gt; &lt;DataGrid.Columns&gt; &lt;DataGridTextColumn Header="Nom" Binding="{Binding Nom}" Width="150" IsReadOnly="True"/&gt; [...] &lt;/DataGrid&gt; &lt;Button Name="BoutonSynchro" Style="{StaticResource MessageBoxButtonStyle}" Content="Synchroniser" Height="27" Width="107" Command="{Binding BoutonSynchro}" CommandParameter="GridComposants" Visibility="{Binding Etat, Converter={StaticResource VisibilityConverter}}"/&gt; &lt;/Canvas&gt; </code></pre> <p></p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload