开发者

MVVM for a silverlight page with dynamic input controls

Say you have a xaml page that takes two inputs such as DATE and some TEXT value and displays the result on a DataGrid, its easy to have a class with with 3 properties of dataTypes DateTime, string 开发者_Python百科and some Collection and implement the same in MVVM.

I have a xaml page with a DataGrid and few input controls(like textbox or datepicker) generated dynamically based on a certain criteria. I want to implement this in a MVVM pattern but not sure how to go about. Any pointers will be helpful.


In my experience, MVVM is not answer for all presentation scenarios, sometimes you just have to use codebehind or build custom control. I would suggest here building custom control that takes (binds with dependency property) object or list of objects, and generates controls (text boxes with input validation/verification, for ints, doubles, date picker, etc), and binds given object to them. In the end you will have one smart control that takes object and renders input fields, and binds to them. Your VM class would just expose object or list of objects.


It is always good to separate the view and the model; however this cannot always be done with simple data binding of simple types.

I would be looking at something like a custom control that could databind to a list of {name, value, spec} pairs when the “spec” is the logical type of control to use.

Thinking about it; that is like what a property grid does if you pass it a custom collection of property descriptors….

Devexpess has a “vertical grid” that may help, also look at 3rd party property grids.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜