在数据网格绑定WPF [英] Datagrid binding in WPF

查看:123
本文介绍了在数据网格绑定WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我知道这已经被问了,不过我已经做几乎所有的东西是什么开发商建议。

I know this has been asked already but I have done almost everything what is suggested by developers.

<DataGrid x:Name="Imported" VerticalAlignment="Top" DataContext="{Binding Source=list}"  AutoGenerateColumns="False" CanUserResizeColumns="True">
        <DataGrid.Columns>                
            <DataGridTextColumn Header="ID" Binding="{Binding Path=ID}"/>
            <DataGridTextColumn Header="Date" Binding="{Binding Path=Date}"/>
           </DataGrid.Columns>
    </DataGrid>

我想在模态对话框,显示这一点,并在模态对话框的构造函数中填充许可证列表。
但仍没有得到被填充数据网格中。

I am trying to show this in modal dialog box and populating the license list in the constructor of the modal dialog box. But still nothing is getting populated inside the datagrid.

构造code:

public diagboxclass()
{
    List<object> list = new List<object>();
    list = GetObjectList();
}

public class object
{
    string id;
    DateTime date;
    public string ID
    {
        get { return id; }
        set { id = value; }
    }
    public DateTime Date
    {
        get { return date; }
        set { date = value; }
    }
}

你们认为是与对象列表?

Do you guys think something to do with the object list?

推荐答案

在没有看到说对象名单,我相信你应该是绑定到DataGrid的的ItemsSource 属性,而不是它的的DataContext

Without seeing said object list, I believe you should be binding to the DataGrid's ItemsSource property, not its DataContext.

<DataGrid x:Name="Imported" VerticalAlignment="Top" ItemsSource="{Binding Source=list}"  AutoGenerateColumns="False" CanUserResizeColumns="True">
    <DataGrid.Columns>                
        <DataGridTextColumn Header="ID" Binding="{Binding ID}"/>
        <DataGridTextColumn Header="Date" Binding="{Binding Date}"/>
   </DataGrid.Columns>
</DataGrid>

(这个假设包含DataGrid中的元素[用户控件等]有及其的DataContext绑定到包含列表中的对象集合。数据网格是由的ItemsControl 导出,这依赖于它的的ItemsSource 属性来定义它结合其行到集合。因此,如果列表未绑定到你的控件的DataContext的一个对象的属性,您可能需要同时设置的DataContext = {绑定列表} 的ItemsSource = {绑定列表} 在DataGrid中...)

(This assumes that the element [UserControl, etc.] that contains the DataGrid has its DataContext bound to an object that contains the list collection. The DataGrid is derived from ItemsControl, which relies on its ItemsSource property to define the collection it binds its rows to. Hence, if list isn't a property of an object bound to your control's DataContext, you might need to set both DataContext={Binding list} and ItemsSource={Binding list} on the DataGrid...)

这篇关于在数据网格绑定WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆