title: Binding List of Items in WPF
body: <p>I try to realize MVVM. TextBox text in View is Binded to property itemName in Model.</p>
  
  <p>On view is DataGrid -> Binded to ViewModel.Rows property</p>
  
  <p>In ViewModel on itemName on change event run async request to remote service for products, which is goes to model SugestProducts property. SugestProducts property is source for ListView items. </p>
  
  <p>If products more than 0 listview open. ListView SelectedItem is Binded to model product property. </p>
  
  <p>I need on product selection in list view fill itemName property from Product.name property without request to remote service. Other work good. </p>
  
  <p>My model is:</p>
  
  <pre><code>public class RowDocumentSaleWraper : INotifyPropertyChanged
  {
      private ObservableCollection&lt;Product&gt; _sugestProducts;
      public ObservableCollection&lt;Product&gt; SugestProducts 
      { 
          get
          {
              return _sugestProducts;
          }
          set
          {
              _sugestProducts = value;
              NotifyPropertyChanged("SugestProducts");
          }
      }
  
          public Product product {get; set;}
           _itemName
          public override string itemName
          {
              get
              {
                  return itemName;
              }
              set
              {
                  itemName = value;
                  NotifyPropertyChanged("itemName");
              }
          }  
          public event PropertyChangedEventHandler PropertyChanged;
          private void NotifyPropertyChanged(String propertyName = "")
          {
              if (PropertyChanged != null)
              {
                  PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
              }
          }
  }
  </code></pre>
  
  <p>Product:</p>
  
  <pre><code>public class Product
  {
      public string name{get; set;}
  }
  </code></pre>
  
  <p>My ViewModel Is:</p>
  
  <pre><code>public class OrderViewModel : DependencyObject
  {
         public ObservableCollection&lt;RowDocumentSaleWraper&gt; Rows { get; set; }
  
      public OrderViewModel()
      {
          addNewRow();
      }
          internal void addNewRow()
          {
              RowDocumentSaleWraper row = new RowDocumentSaleWraper(Order);
              row.PropertyChanged += row_PropertyChanged;
              Rows.Add(row);
          }
      void row_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e)
      {
          RowDocumentSaleWraper row = sender as RowDocumentSaleWraper;
  
          if (row != null &amp;&amp; e.PropertyName == "itemName" &amp;&amp; !String.IsNullOrEmpty(row.itemName))
          {
              //get products from remote service -&gt; source for 
              requestProducts(row.itemName, row);
          }
      }
      private async void requestProducts(string searchString, RowDocumentSaleWraper row)
      {
          if (!String.IsNullOrEmpty(searchString))
          {
              var products = await requestProductsAsync(searchString);
  
              row.SugestProducts = listToObservable(products);
          }
  
      }
  }
  </code></pre>
  
  <p>My Xaml:</p>
  
  <pre><code>&lt;DataGrid Grid.Row="1" Name="mainDataGrid" ItemsSource="{Binding Rows , UpdateSourceTrigger=PropertyChanged}" AutoGenerateColumns="False" CanUserAddRows="False"&gt;
  &lt;DataGrid.Columns&gt;
  &lt;DataGridTemplateColumn Header="Product"&gt;
                      &lt;DataGridTemplateColumn.CellTemplate&gt;
                          &lt;DataTemplate&gt;
                              &lt;StackPanel Orientation="Vertical"&gt;
                                  &lt;TextBox PreviewKeyDown="TextBox_PreviewKeyDown" KeyDown="TextBox_KeyDown" Text="{Binding itemName, UpdateSourceTrigger=PropertyChanged}" MinWidth="200"/&gt;
                                  &lt;ListView ItemsSource="{Binding SugestProducts, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"  
                                            KeyDown="ListView_KeyDown" SelectedItem ="{Binding product, UpdateSourceTrigger=PropertyChanged}"&gt;
                                      &lt;ListView.View&gt;
                                          &lt;GridView ColumnHeaderContainerStyle="{StaticResource myHeaderStyle}"&gt;
                                              &lt;GridViewColumn  DisplayMemberBinding="{Binding code}"/&gt;
                                              &lt;GridViewColumn  DisplayMemberBinding="{Binding name}" /&gt;
                                          &lt;/GridView&gt;
                                      &lt;/ListView.View&gt;
                                  &lt;/ListView&gt;
                              &lt;/StackPanel&gt;
                          &lt;/DataTemplate&gt;
                      &lt;/DataGridTemplateColumn.CellTemplate&gt;
                  &lt;/DataGridTemplateColumn&gt;
              &lt;/DataGrid.Columns&gt;
          &lt;/DataGrid&gt;
  </code></pre>