Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I'm just starting to get this, but this has worked so far.</p> <pre><code> &lt;DataGrid CanUserAddRows="True" CanUserDeleteRows="True" ItemsSource="{Binding UserAlerts}" IsSynchronizedWithCurrentItem="True" x:Name="UserAlertsGrid"&gt; &lt;DataGrid.Columns&gt; &lt;DataGridTextColumn Header="Node ID" Binding="{Binding Node_id}"&gt;&lt;/DataGridTextColumn&gt; &lt;DataGridTextColumn Header="Threshold" Binding="{Binding Threshold}"&gt;&lt;/DataGridTextColumn&gt; &lt;DataGridTextColumn Header="Type of Alert" Binding="{Binding TypeOfAlert}"&gt;&lt;/DataGridTextColumn&gt; &lt;/DataGrid.Columns&gt; &lt;/DataGrid&gt; </code></pre> <p>Then to get the 'CanUserAddRows' to work, you need a default constructor in your ViewModel (where you do the bindings). If there is no default constructor, you won't get a blank row.</p> <pre><code> class UserAlertViewModel : BaseViewModel { private readonly UserAlert _alertItem; public UserAlertViewModel() { _alertItem = new UserAlert(); } public UserAlertViewModel(UserAlert alertItem) { _alertItem = alertItem; } public int Node_id { get { return _alertItem.Node_id; } set { _alertItem.Node_id = value; OnPropertyChanged("Node_id"); } } public double Threshold { get { return _alertItem.Threshold; } set { _alertItem.Threshold = value; OnPropertyChanged("Threshold"); } } public string TypeOfAlert { get { return _alertItem.TypeOfAlert; } set { _alertItem.TypeOfAlert = value; OnPropertyChanged("TypeOfAlert"); } } } </code></pre> <p>And in the actual Window, you have to set the DataContext for the DataGrid</p> <pre><code>public UserAlertWindow() { InitializeComponent(); this.DataContext = new ViewModel.UserAlertWindowViewModel(); UserAlertsGrid.DataContext = new ViewModel.UserAlertWindowViewModel(this); } </code></pre> <p>And for updating the database when the user edits or deletes, check this link, it looks very promising. <a href="http://www.dotnetcurry.com/ShowArticle.aspx?ID=566" rel="nofollow">http://www.dotnetcurry.com/ShowArticle.aspx?ID=566</a></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