我刚刚开始使用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'
答案 0 :(得分:0)
SampleData
应该是返回DataContext
的{{1}}(或父元素)的DataGrid
的属性。试试这个:
IEnumerable<SampleData>