在WP7中使用DataGrid

时间:2011-11-25 07:20:38

标签: c# windows-phone-7 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.

1 个答案:

答案 0 :(得分:2)

您显示的异常似乎与您未显示的某些XAML有关。 x:Class附加属性表示用户控件的代码隐藏类。类型projectName.MainPage是否会退出项目?

我建议您重新使用新的用户控件,减慢添加代码的速度,重新编译并在慢慢添加代码时运行。

相关问题