Closing a radpad from a viewmodel mvvm

3 posts, 1 answers
  1. Randy Hompesch
    Randy Hompesch avatar
    70 posts
    Member since:
    Nov 2008

    Posted 04 Nov 2016 Link to this post

    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. Answer
    Nasko avatar
    698 posts

    Posted 07 Nov 2016 Link to this post

    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.

    Telerik by Progress
    Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
  3. Randy Hompesch
    Randy Hompesch avatar
    70 posts
    Member since:
    Nov 2008

    Posted 09 Nov 2016 in reply to Nasko Link to this post

    Hah, I knew there had to be some magic sauce. That's exactly what I needed. Thanks.
Back to Top