This is a migrated thread and some comments may be shown as answers.

Save Docking Layout - MVVM

3 Answers 310 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 10 Jan 2014, 04:54 PM
The save load layout example is not mvvm. The example uses code behind to call the SaveLayout and LoadLayout on the docking control and it does not use a view model. Where is an example of radDocking save and load layout using no code behind. ?

3 Answers, 1 is accepted

Sort by
0
Vladi
Telerik team
answered on 13 Jan 2014, 02:00 PM
Hi Eric,

Thank you for contacting us.

Our online SDK example about Save and Load of the RadDocking's layout is intended to showcase the built-in functionality in the simplest way possible which is why it is not implemented in a MVVM manner but rather uses simple Button Click events. You can easily move the logic from those events to a ViewModel and instead of using the Click events of the Button create a custom ICommand and set it to their Command property. In order to pass the RadDocking control itself you can simply bind the control to the CommandParameter of the Buttons.

I created and attached a sample project for you of the described approach, hope this is helpful. If you have any other questions feel free to write to us again.

Regards,
Vladi
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Eric
Top achievements
Rank 1
answered on 14 Jan 2014, 02:52 PM
Thanks, this won't work unfortunately. There is no button. I need to save layout on shut down of a composite application in response to an aggregate event. The only way I can see to do that in an MVVM fashion is to add a reference to the docking control to the view model in code behind when the user control loads. This breaks the rules and cannot be unit tested. The rad docking control needs a way to trigger a save layout and bind the output to a property on the view model. 

Can you explain to me what CurrentSaveLoadLayoutHelper is used for? The documentation doesn't give an example.

We need a OnSaveLayoutCommand and OnLoadLayoutCommand properties on the docking control. You cannot just assume the view will support a button. This is also the case with the IsHidden property for RadPane. If you hide the pane, the data context is broken so you have to use a hidden checkbox to bind the IsHidden property to the checked property. Most UI developers need to show and hide panes by menu, not a checkbox or a button.
0
Vladi
Telerik team
answered on 15 Jan 2014, 02:03 PM
Hi Eric,

In WPF any UI control cannot provide a built-in functionality that automatically notifies the ViewModel when one of its events are triggered without any interaction with those event. In order to achieve this behavior you could use any of the Event to Command approaches that could be found on the web. Recently we introduced EventToCommandBehavior that could be useful in this case. You could attached one command from your ViewModel to the Loaded event of the RadDocking and one to the Closing event of the MainWindow. I updated the previously attached sample project with the described approach.

The CurrentSaveLoadLayoutHelper is provided in order to be able to create a custom class that inherits the SaveLoadLayoutHelper class and override its methods.

Regards,
Vladi
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
Tags
Docking
Asked by
Eric
Top achievements
Rank 1
Answers by
Vladi
Telerik team
Eric
Top achievements
Rank 1
Share this question
or