开发者

WPF DataGrid and parameterless constructors

I have a class "MyEntity", which does not have a default constructor (well, it does, yet it is not suitable for use).

I have a form with a DataGrid, which has a cool feature for creating new rows.

Problem: DataGrid cannot create new object when no parameterless constructor is defined.

Question: is there a way to provide the DataGrid w开发者_如何转开发ith a Func that would construct the new object (= some factory method like CreateObject)? Or is there some other solution?

PS Adding a default constructor is not an option - it is not suitable for my purposes. POCO in EF4 requires objects to be created through a context factory class (calling CreateObject).


Wrap your MyEntity class in another class (MyEntityWrapper) with a default constructor and databind the grid to a collection of MyEntityWrapper objects. Put it in a VM to keep you view (the grid) and model (the collection of MyEntity object) clean.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜