English 中文(简体)
数据分析如何约束任何收集的财产?
原标题:How does DataGrid bind to properties of any collection?

我正在对WPF用户进行控制,我希望像数据Grid控制那样具有约束性。 我的问题是:数据分析如何知道如何对任何类型一E的收集进行约束? 例如: 您可以作为项目通过数据意见,也可以通过任何物体收集。 数据组如何决定是否仅通过研究对数据一栏或对物体财产具有约束力:

<DataGridTextColumn Binding="{Binding **Path=SomePropertyOrColumn**}"/>

提前感谢。

最佳回答

这是一个复杂的领域;下面是具有约束力的双赢模式的明细,但我理解,《世界森林框架》的约束力是有差异的;

  • given an object, the first thing binding code will do is look for IListSource - and if so use GetList() to get the actual binding (this is how a data-table becomes a data-view for binding purposes)
  • after that, the source is typically checked for ITypedList; this acts as a flexible way of obtaining pseudo-properties (GetItemProperties()) represented by the model; data-view implements ITypedList, creating pseudo-properties per instance
  • otherwise, it might be possible to identify an obvious type for the data, which can mean:
    • looking for an indexer of the form public SomeType this[int index] {get;} - note that most collections will satisfy this
    • (not done by winforms, but might be for WPF) resolving via reflection the T in either IList<T> or IEnumerable<T> if the object implements those interfaces
    • taking the first object (if any) from the sorce, and using GetType()
  • once a type is known, TypeDescriptor.GetProperties(type) can be used to obtain properties; in many cases this will be via reflection, but it is also possible to add an indirection layer (via TypeDescriptionProvider) to supply properties for a type (this can be added at runtime, which can be very convenient)
  • in the case of individual binding (not list binding), there is also TypeDescriptor.GetProperties(obj) - in addition to reflection and TypeDescriptionProvider, this also has support for ICustomTypeDescriptor which can be implemented by an individual object to supply custom properties at runtime (very similar to TypeDescriptionProvider, but with the individual object taking responsibility for the properties)

我并不确切地知道其中多少适用于具有约束力的世界森林论坛,但我确信,ITypedList处理是相同的。 从记忆中,大多数(所有吗?)的双赢战略都将在森林伙伴关系方面发挥作用,因此,变化可以是additionalhooks。

问题回答

www.un.org/Depts/DGACM/index_spanish.htm 我认为:

you can get Type of element of its Collection, this type Type have GetProperties() method, which returns all public properties available in its type, and, after its know all public properties, it can bind with them.





相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签