Closing a radpad from a viewmodel mvvm

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

    Posted 04 Nov 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
    Admin
    Nasko avatar
    588 posts

    Posted 07 Nov 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.

    Regards,
    Nasko
    Telerik by Progress
    Do you need help with upgrading your WPF project? Try the Telerik API Analyzer and share your thoughts!
  3. UI for WPF is Visual Studio 2017 Ready
  4. Randy Hompesch
    Randy Hompesch avatar
    46 posts
    Member since:
    Nov 2008

    Posted 09 Nov 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