-1


当我调用headersDataGrid.ItemsSource应用程序时抛出异常。有人可以帮我调试并确定错误是什么吗?谢谢

代码

public static List<Item> getHeaders()
    {
        Item i1 = new Item();
        i1.Label = "TST";
        i1.Description = "This header is only for testing";
        Item i2 = new Item();
        i2.Label = "TS2";
        i2.Description = "This is the second header and is used for testing purposes :)";
        Item i3 = new Item();
        i3.Label = "TS3";
        i3.Description = "This is the THIRD header and is used for testing purposes :D";
        List<Item> headers = new List<Item>();
        headers.Add(i1);
        headers.Add(i2);
        headers.Add(i3);
        return headers;
    }



    public MainWindow()
    {
        displayHeaders();
        InitializeComponent();
    }

    /// <summary>
    /// The purpose of this method is to display all of the headers
    /// </summary>
    public void displayHeaders()
    {
        //List<Item> headers = Database.getHeaders();

        // Testing Purposes
        List<Item> headers = TestingClass.getHeaders();

        // Handle Headers
        headersDataGrid.ItemsSource = headers;          
    }

XML

            <Grid Name="grid_headers" Background="Honeydew">
                <DataGrid x:Name="headersDataGrid" AutoGenerateColumns="True"></DataGrid>
            </Grid>
4

1 回答 1

1

该错误表明headersDataGrid为空。尝试在初始化组件调用后移动 displayHeaders 方法。

于 2013-09-03T21:51:02.200 回答