在WPF中将对象属性绑定到数据网格 [英] Bind object properties to a datagrid in WPF

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

问题描述

我有以下课程:

public class Sp3dItem
{
    public Sp3dItem()
    {
        Items= new ObservableCollection<Sp3dItem>();
    }

    public string OID
    {
        get;
        set;
    }

    public string Name
    {
        get;
        set;
    }

    public string Type
    {
        get;
        set;
    }

    public ObservableCollection<Sp3dItem> Items
    {
        get;
        set;
    }
}

我需要显示此实例的属性对象到Datagrid(或任何其他类型的网格)。类似于Visual Studio中的属性窗口。但是有些属性我不在乎,例如'Items',我只需要显示字符串Type的属性,而只显示那些非空值的属性(这是一个加号,不是真正的需要)。

I need to show the properties of an instance of this object to a Datagrid (or any other type of grid). Like the Properties Window in Visual Studio. But there are certain properties that I don't care, like 'Items', I only need to show properties of string Type, and only the ones with non empty values (this last one would be a plus, not a real need).

问题是,可以通过绑定执行类似的操作,还是必须手动将数据组装到网格上?

The question is, can I do something like this with binding or do I have to assembly the data on the grid manually?

推荐答案

听起来像您希望属性网格查看单个对象实例的属性,其中每个属性/值对都是一个行 ,是吗?如果是这种情况,请查看一些第三方属性网格控件。 WPF扩展工具包有一个免费的工具。

Sounds like you want a property grid to view the properties of a single object instance, where each property/value pair is a 'row', yes? If that's the case, look into some of the third-party Property Grid controls. The WPF Extended Toolkit has a free one.

通常,这些网格可以自动发现目标对象的属性,并且您可以选择隐藏某些属性,方法是使用 [Browsable(false)] 装饰它们

Typically, these grids can automatically discover the properties of the target object, and you can choose to hide certain properties by adorning them with [Browsable(false)].

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

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