I have a WPF /MVVM application. I need to put 2 buttons, Expand All and Collapse All above the grid. I need an example of binding each row's expanded property to a view model.
Thank you
3 Answers, 1 is accepted
0
Yoan
Telerik team
answered on 10 Mar 2014, 06:36 PM
Hi Kevin,
Generally, you can use GridView's ExpandAllHierarchyItems and CollapseAllHierarchyItems methods. As for binding of GridViewRow's IsExpanded - you can bind it to a property of your business object by subscribing to GridView's RowLoaded event. It will be something similar to this:
Subscribing to an event means I now have data code in the code behind for the view, which is not MVVM. Is there not a row template with an IsExpanded property that I can bind to?
0
Yoan
Telerik team
answered on 10 Mar 2014, 07:25 PM
Hi Kevin,
If you want to have your code-behind clean, the way to go is with an Attached behavior. Hereyou can find information about it. You will write the attached behavior only once. This attached behavior will attach to the event and will set the binding. Then you can enable this attached behavior on a RadGridView. Here is a very nice article about event handling with attached behaviors. You have the code in one place only. All you will need to do is something like this:
<RadGridView EnableMyAttachedBehavior="True"/> and then let the attached behavior kick in and do its job.
Regards,
Yoan
Telerik
DevCraft Q1'14 is here! Watch the online conference to see how this release solves your top-5 .NET challenges.Watch on demand now.