开发者

Can Telerik RADGridView be used without in pure MVVM fashion without any code behind?

I am using Telerik's Silverlight RADGridView control and trying to imple开发者_运维技巧ment it in a pure MVVM fashion. I am using MVVMLight's EventToCommand to pass the control's events to my viewmodel.

In particular, I am trying to handle the AddingNewDataItem event.

While MVVMLight's PassEventArgsToCommand works fine, none of the changes I make to the argument get passed back up to the grid control (in particular the NewObject parameter). If I manipulate NewObject in code behind, everything works fine.

Does anyone have any experience in getting this to work? As of right now it looks like Telerik only 'kinda' supports MVVM, which is unfortunate.


Having code in the code-behind behind does mean that the code departs from the MVVM pattern. It is perfectly legitimate to have code in the code-behind as long at the purpose of the code is manipulating the UI and not referencing any problem domain data. In fact, it would be wrong to put UI manipulation in the ViewModel.

It is not clear exactly what you are trying to accomplish, but if you are passing a reference to GridViewRowEditEndedEventArgs to your ViewModel, that is a departure from the MVVM pattern because the ViewModel is now dependent on the View implementation.

In the MVVM pattern the View 'knows about' the ViewModel and the ViewModel 'knows about' the Model. But the Model is not dependent on or know about the ViewModel and the ViewModel is not dependent on or know about the View.

If you are passing a GridViewRowEditEndedEventArgs reference to the ViewModel the problem is that if/when you change the view to some other control (like RadListBox, Infragistics grid control, or anything) your ViewModel will cease to correctly function.

Your statement that:

Telerik only 'kinda' supports MVVM

is unfair and incorrect.

The goal of MVVM is not to eliminate code from the code-behind. This a common misconception. The goals of MVVM are to promote testability and remove domain & model logic from the code behind as part of good 'separation of concerns' practices.

When the code-behind code is simply moved to class named SomethingSomethingViewModel... that is not MVVM.


Eric, I am using the Silverlight GridView control with MVVMLight and have been able to get it to work successfully.

I think your problem might be more the understanding of the AddingNewDataItem event. If you take a look at the documentation for Adding New Entries you will see that

The AddingNewDataItem is raised before the new row is displayed. In the event handler you initialize the object that has to be added and pass it to the GridViewAddingNewEventArgs.

Once you have your initialised object you then need to handle the RowEditEnded event as well to commit or cancel the changes you have made. Again, if you take a look at the Telerik documentation you will see that you have access to the object you created in the AddingNewDataItem event through the GridViewRowEditEndedEventArgs (e.NewData). Also, when the new item is committed, it will be automatically added to the RadGridView's Items.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜