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

Closing a radpad from a viewmodel mvvm

2 Answers 55 Views
Docking
This is a migrated thread and some comments may be shown as answers.
Randy Hompesch
Top achievements
Rank 1
Randy Hompesch asked on 04 Nov 2016, 07:23 PM

Ok, so I'm doing a vstudio-like interface using raddocking. I have a pane group on the left and right and mode of the user interaction will be with the right group.

I also have a radmenu and radtoolbar at the top of the main window. I have a File/Close menu option. It's bound to a CloseCommand in my MainWindow's viewmodel but I get stuck there.

Using MVVM, how best to close the RadPane? I can add the EventToCommandBehavior to the xaml. Then I can catch the command in my MainWindow's ViewModel. The problem is that once I'm in the ViewModel, I don't know how to tell the RadPane's View to close the pane in such a way that it's PreviewClose event fires so I can test to see if the user wants to save changes etc. Supposedly, in MVVM, you're not supposed to be playing with UI stuff in the VM.

To put it more simply, I want to ask the user if they need to save changes when the hit file close. I don't see how to do that in a VM without breaking MVVM rules.

Even using the examples seem to break MVVM rules. Passing a radpane to a command seems like it breaks MVVM rules.

Any insight would be greatly appreciated. (BTW, we are using prism). I am new to MVVM and right now, it seems very difficult to do simple stuff.

Thanks ... Ed

 

2 Answers, 1 is accepted

Sort by
0
Accepted
Nasko
Telerik team
answered on 07 Nov 2016, 08:27 AM
Hello Ed,

When the Close button of a Pane gets pressed actually its IsHidden property is set to True - thus the Pane could easily be made visible again when it is needed. So, in order to close the Pane as desired an trigger the PreviewClose event you just need to set the IsHidden property of the desired and needed Pane to True. The IsHidden property is boolean and could easily be bound without breaking the pattern.

Please, check the attached sample that demonstrates the described above approach.

We hope this will help you.

Regards,
Nasko
Telerik by Progress
Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
0
Randy Hompesch
Top achievements
Rank 1
answered on 09 Nov 2016, 11:33 AM
Hah, I knew there had to be some magic sauce. That's exactly what I needed. Thanks.
Tags
Docking
Asked by
Randy Hompesch
Top achievements
Rank 1
Answers by
Nasko
Telerik team
Randy Hompesch
Top achievements
Rank 1
Share this question
or