1
我需要在datagrid中顯示我的數據。我使用下面的代碼:在WP7中使用DataGrid
前端:
命名空間:xmlns:datagrid="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data"
<datagrid:DataGrid Name="tgrid" AutoGenerateColumns="False" Grid.Row="2" HeadersVisibility="Column">
<datagrid:DataGrid.Columns>
<datagrid:DataGridTextColumn Header="Name">
</datagrid:DataGridTextColumn>
</datagrid:DataGrid.Columns>
</datagrid:DataGrid>
後端:
List<LItem> str = new List<LItem>();
str.Add(new LItem() { Str = "chandra" });
str.Add(new LItem() { Str = "chandra" });
str.Add(new LItem() { Str = "chandra" });
str.Add(new LItem() { Str = "chandra" });
str.Add(new LItem() { Str = "chandra" });
str.Add(new LItem() { Str = "chandra" });
tgrid.ItemsSource = str;
public class LItem
{
private string _str;
public string Str
{
get { return _str; }
set { _str = value; }
}
}
當我使用此代碼我得到一個例外,因爲:
The type 'projectName.MainPage', specified in the x:Class of '/MainPage.xaml' could not be found in any loaded assembly.
projectName.MainPage存在於我的項目中。當我評論datagrid部分時,程序照常執行。 –