Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
345
How to use XamDialog with MVVM
posted

I would like to use XamDialog in my project but it seems the dialog must be in the visualtree before you can call Show.  My project uses MVVM and the logic that determines when to show the modal is in my vm.  Is it possible to use XamDialog with mvvm

 

Thanks in advance

Will

  • 5170
    Offline posted

    There's a better way.  I just blogged about how to show the XamDialogWindow in a ViewModel without it being part of the visual tree.  Of course, as the post says, I would still use a Dialog Service to show the dialog as your VM should be ignorant to Views.

     

    http://brianlagunas.com/2013/05/18/showing-the-xamdialogwindow-from-a-viewmodel-in-silverlight-and-wpf/

  • 34510
    Verified Answer
    Offline posted

    Hi Will,

    The simplest way you can do this is have a delegate in your view model that is hooked up to a method in your view.  This method will take in an argument of type object that will be your data context for the dialog window.  In your view model, whenever you want to show the dialog you would just call the delegate.

    This way maintains MVVM because your view model doesn't know anything about what the delegate actually does and the method in your view is just showing a XamDialogWindow which is just UI code anyway.

    Let me know if you have any questions on this.

  • 34510
    Offline posted

    Hi Will,

    I'm looking into this for you and will get back to you tomorrow.