title: How to resolve a "Binding Expression Path error" in WPF?
body: <p>I'm binding an observsable collection of model objects to a data grid. But when I set the binding to the collection, I get a path error to the peoprties.</p>
  
  <p>In debugging this issue, I've checked that the public properties in the CustomerModel are correctly named in the DataGrid binding. And also that the collection being returned to the model isn't empty. I also checked that the data context is set correctly in the View's code behind.</p>
  
  <p>I think it might be an error due to the way I've specified the binding path in the xaml..</p>
  
  <p>The full details of the binding error is as follows, for each field:</p>
  
  <pre><code>System.Windows.Data Error: 40 : BindingExpression path error: 'FirstName' property not found on 'object' ''MainViewModel' (HashCode=55615518)'. BindingExpression:Path=FirstName; DataItem='MainViewModel' (HashCode=55615518); target element is 'TextBox' (Name='fNameTbx'); target property is 'Text' (type 'String')
  
  System.Windows.Data Error: 40 : BindingExpression path error: 'LastName' property not found on 'object' ''MainViewModel' (HashCode=55615518)'. BindingExpression:Path=LastName; DataItem='MainViewModel' (HashCode=55615518); target element is 'TextBox' (Name='lNameTbx'); target property is 'Text' (type 'String')
  
  System.Windows.Data Error: 40 : BindingExpression path error: 'Email' property not found on 'object' ''MainViewModel' (HashCode=55615518)'. BindingExpression:Path=Email; DataItem='MainViewModel' (HashCode=55615518); target element is 'TextBox' (Name='emailTbx'); target property is 'Text' (type 'String')
  </code></pre>
  
  <p>Could anyone point me in the right direction, in order to debug this further?</p>
  
  <p>DataGrid binding path and source are set as follows:</p>
  
  <pre><code>                   &lt;DataGrid Name="infogrid"
                                Grid.Row="0"
                                Grid.RowSpan="3"
                                Grid.Column="1"
                                Grid.ColumnSpan="3"
                                AutoGenerateColumns="False"
                                ItemsSource="{Binding Customers}"
                                SelectedItem="{Binding SelectedCustomer}"&gt;
                          &lt;DataGrid.Columns&gt;
                              &lt;DataGridTextColumn Binding="{Binding Customers.Id}" Header="ID" /&gt;
                              &lt;DataGridTextColumn Binding="{Binding Customers.FirstName}" Header="First Name" /&gt;
                              &lt;DataGridTextColumn Binding="{Binding Customers.LastName}" Header="Last Name" /&gt;
                              &lt;DataGridTextColumn Binding="{Binding Customers.Email}" Header="Email" /&gt;
                          &lt;/DataGrid.Columns&gt;
                      &lt;/DataGrid&gt;
  </code></pre>
  
  <p>The View Model contains an Observable collection of type CustomerModel, called Customers. This is what I've set the DataGrid ItemSource to. (I've removed other code from VM for readability)</p>
  
  <pre><code>namespace MongoDBApp.ViewModels
  {
  
      class MainViewModel : INotifyPropertyChanged
      {
  
          public event PropertyChangedEventHandler PropertyChanged = delegate { };
          private ICustomerDataService _customerDataService;
  
  
          public MainViewModel(ICustomerDataService customerDataService)
          {
              this._customerDataService = customerDataService;
              QueryDataFromPersistence();
          }
  
  
  
          private ObservableCollection&lt;CustomerModel&gt; customers;
          public ObservableCollection&lt;CustomerModel&gt; Customers
          {
              get
              {
                  return customers;
              }
              set
              {
                  customers = value;
                  RaisePropertyChanged("Customers");
              }
          }
  
  
  
          private void QueryDataFromPersistence()
          {
              Customers = _customerDataService.GetAllCustomers().ToObservableCollection();
  
          }
  
  
  
          private void RaisePropertyChanged(string propertyName)
          {
              if (PropertyChanged != null)
              {
                  PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
              }
          }
  
  
  
      }
  }
  </code></pre>
  
  <p>And these are the fields that in the CustomerModel, so not sure why the properties are not being found during binding:</p>
  
  <pre><code>   public class CustomerModel : INotifyPropertyChanged
      {
  
          private ObjectId id;
          private string firstName;
          private string lastName;
          private string email;
  
  
          [BsonElement]
          ObservableCollection&lt;CustomerModel&gt; customers { get; set; }
  
          /// &lt;summary&gt;
          /// This attribute is used to map the Id property to the ObjectId in the collection
          /// &lt;/summary&gt;
          [BsonId]
          public ObjectId Id { get; set; }
  
          [BsonElement("firstName")]
          public string FirstName
          {
              get
              {
                  return firstName;
              }
              set
              {
                  firstName = value;
                  RaisePropertyChanged("FirstName");
              }
          }
  
          [BsonElement("lastName")]
          public string LastName
          {
              get
              {
                  return lastName;
              }
              set
              {
                  lastName = value;
                  RaisePropertyChanged("LastName");
              }
          }
  
          [BsonElement("email")]
          public string Email
          {
              get
              {
                  return email;
              }
              set
              {
                  email = value;
                  RaisePropertyChanged("Email");
              }
          }
  
  
          public event PropertyChangedEventHandler PropertyChanged;
          private void RaisePropertyChanged(string propertyName)
          {
              if (PropertyChanged != null)
              {
                  PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
              }
          }
      }
  </code></pre>
  
  <p>This is how the data context is set in the View's code behind:</p>
  
  <pre><code>    public partial class MainView : Window
      {
          private MainViewModel ViewModel { get; set; }
          private static ICustomerDataService customerDataService = new CustomerDataService(CustomerRepository.Instance);
  
  
          public MainView()
          {
              InitializeComponent();
              ViewModel = new MainViewModel(customerDataService);
              this.DataContext = ViewModel;
  
          }
  
      }          
  </code></pre>