我知道我张贴了这个问题,但已接受我的最后一个问题的答案,并通过我意识到这不是我一直在寻找答案的文章如下。我再次发布了一些示例代码。WPF8/C# - 将数据绑定到网格
我想从一个集合填充网格(不是一个DataGrid)使用数据。这是我的,但它不起作用。如果我删除集合并将DataContext设置为单个对象,但不能作为集合。
XAML
Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<StackPanel>
<TextBlock Text="{Binding Path=StudentName}" />
</StackPanel>
</Grid>
MainPage.xaml.cs中
public MainPage()
{
InitializeComponent();
ObservableCollection<Student> ob = new ObservableCollection<Student>();
ob.Add(new Student()
{
StudentName = "James Jeffery"
});
ob.Add(new Student()
{
StudentName = "Sian Ellis"
});
this.DataContext = ob;
// Sample code to localize the ApplicationBar
//BuildLocalizedApplicationBar();
}
这已被窃听我小时。我似乎无法用集合填充网格。 Google上的每个示例都显示了ListView等。我想填充一个Grid,并且只填充一个Grid。
有关如何实现此目的的任何建议?
看起来您没有为Grid的ItemsSource设置数据上下文。 – Reddog 2013-03-19 00:06:27