我知道我張貼了這個問題,但已接受我的最後一個問題的答案,並通過我意識到這不是我一直在尋找答案的文章如下。我再次發佈了一些示例代碼。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