Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I'm guessing here since your question is a little vague that you're not quite sure how to hook the pieces together. For simplicity's sake let us hook the ViewModel directly to the user control and get it all binding.</p> <p>As long as your view model is populated with the correct set of People, all the binding below will handle the data and show the correct data. Take note of the two-way binding for the selected item in the combobox. That allows WPF to send back the new selected item to the viewmodel.</p> <p>In the UserControl's code behind:</p> <pre><code>public MyUserControl() { DataContext = new MyViewModel(); } </code></pre> <p>In the UserControl's XAML:</p> <pre><code>&lt;ComboBox ItemsSource="{Binding AllPeople}" SelectedItem="{Binding SelectedItem, Mode=TwoWay}" /&gt; &lt;TextBox Text="{Binding SelectedItem.LastName}" /&gt; &lt;TextBox Text="{Binding SelectedItem.FirstName}" /&gt; &lt;TextBox Text="{Binding SelectedItem.EmailName}" /&gt; </code></pre> <p>Your ViewModel:</p> <pre><code>private IEnumerable&lt;Person&gt; _allPeople; public IEnumerable&lt;Person&gt; AllPeople { get { return _allPeople; } set { if (_allPeople != value) { _allPeople = value; NotifyPropertyChanged("AllPeople"); } } } private Person _selectedItem; public Person SelectedItem { get { return _selectedItem; } set { if (!_selectedItem != value) { _selectedItem = value; NotifyPropertyChanged("SelectedItem"); } } } private void NotifyPropertyChanged(string propertyName) { if ( PropertyChanged != null) { PropertyChanged(this, new PropertyChangedEventArgs(propertyName); } } } public class Person { public int PersonId { get; set; } public string FirstName { get; set; } public string LastName { get; set; } public string Email { get; set; } } </code></pre>
    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.
    3. 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