Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Not 100% sure how you are going about this? Usually I would have the grid bound to the selected employee as you have, then have the values of the text boxes bound to the properties on the selectedemployee. As you change row, these would then update to reflect the values of the currently selected row in the grid. So then you add a new blank employee and it would have blank values until they were entered in the text box. Of course, you'd need to build in some validation to ensure you don't get loads of blabnk rows added.</p> <p>If I'm correct in my understanding of how you are wanting to do it, then as it stands the values in the text boxes are not related to the selected row, but are used just to add a new employee with those values? to achieve this I would suggest having the Textbox bind to a string value on the Viewmodel. Currently you have them bound to something that doesn't appear to actually exist. Instead, I'd bind them to their own properties on the view model thus:</p> <pre><code>private string _employeeFirstName; public string EmployeeFirstName { get { return _employeeFirstName; } set { _employeeFirstName= value; RaisePropertyChanged("EmployeeFirstName"); } } </code></pre> <p>and then in the xaml bind to that property - with Mode=TwoWay so that the viewmodel also recieves any updates</p> <pre><code>&lt;TextBox Height="23" HorizontalAlignment="Left" Margin="130,12,0,0" Name="textBox1" VerticalAlignment="Top" Width="120" Text="{Binding Path=EmployeeFirstName, Mode=TwoWay}" /&gt; </code></pre> <p>then when creating your new employee:</p> <pre><code> public void AddEmployee() { Employee newEmployee = new Employee() {FName = this.EmployeeFirstName}; Employees.Add(newEmployee); SelectedEmployee = newEmployee; } </code></pre>
 

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