Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Try using an <code>ObservableCollection&lt;T&gt;</code> instead of the collection you are using now.</p> <p>This should cause the View to be updated whenever an Item is added or removed from the collection.</p> <p>Just remember when interacted with the <code>ObservableCollection</code> to Invoke the Dispatcher otherwise you will get Thread Access Exceptions</p> <p>Here is the code I did to test this.</p> <p>XAML</p> <pre><code>&lt;Window.Resources&gt; &lt;loc:MyViewModel x:Key="ViewModel" /&gt; &lt;/Window.Resources&gt; &lt;Canvas DataContext="{StaticResource ViewModel}"&gt; &lt;DataGrid ItemsSource="{Binding Collection}" Width="150" Height="200"&gt; &lt;DataGrid.Columns&gt; &lt;DataGridTextColumn Header="Nom" Binding="{Binding Nom}" Width="150" IsReadOnly="True" /&gt; &lt;/DataGrid.Columns&gt; &lt;/DataGrid&gt; &lt;Button Command="{Binding DoStuffCommand}" Canvas.Bottom="0" Canvas.Right="0"&gt;Stuff&lt;/Button&gt; &lt;/Canvas&gt; </code></pre> <p>ViewModel</p> <pre><code>public class MyViewModel { public ObservableCollection&lt;MyModel&gt; Collection { get; set; } public ICommand DoStuffCommand { get; set; } public MyViewModel() { this.Collection = new ObservableCollection&lt;MyModel&gt;(); for (int i = 0; i &lt; 10; i++) { Collection.Add(new MyModel { Nom = i.ToString() }); } this.DoStuffCommand = new RelayCommand(DoStuff); } private void DoStuff() { foreach (var item in Collection) { item.Nom = item.Nom + "."; } } } </code></pre> <p>Model</p> <pre><code>public class MyModel : INotifyPropertyChanged { private string nom; public string Nom { get { return nom; } set { nom = value; RaiseChanged("Nom"); } } public event PropertyChangedEventHandler PropertyChanged; private void RaiseChanged(string propertyName) { var handler = PropertyChanged; if (handler != null) { handler(this, new PropertyChangedEventArgs(propertyName)); } } } </code></pre> <p>It updated the Nom in the view.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

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