找不到WPF DataGrid绑定属性

时间:2018-01-08 10:31:37

标签: c# wpf datagrid

我刚刚开始使用WPF,我遇到了向DataGrid显示数据的问题。

WPF(Views \ ResultsPage.xaml):

<DataGrid x:Name="dgResults"
          Margin="2"
          Style="{DynamicResource AzureDataGrid}"
          ItemsSource="{Binding SampleData}"
          AutoGenerateColumns="False"
          RenderOptions.ClearTypeHint="Enabled"
          TextOptions.TextFormattingMode="Display">
   <DataGrid.Columns>
      <DataGridTextColumn Header="Well" Binding="{Binding WellID}"/>
      ..

C#(Data \ SampleData.cs):

public class : INotifyPropertyChanged
{
    private string _wellID;

    public string WellID
    {
        get
        {
            return _wellID;
        }
        set
        {
            _wellID = value;
            NotifyPropertyChanged("WellID");
        }
    }
  ...

public event PropertyChangedEventHandler PropertyChanged;

private void NotifyPropertyChanged(string propertyName)
{
    if (PropertyChanged != null)
    {
        PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
    }
}

我收到此错误: System.Windows.Data错误:40:BindingExpression路径错误:'SampleData'

1 个答案:

答案 0 :(得分:0)

SampleData应该是返回DataContext的{​​{1}}(或父元素)的DataGrid的属性。试试这个:

IEnumerable<SampleData>