Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpenFileDialog using Prism MVVM

Tags:

c#

mvvm

wpf

prism

I am using Prism 6.1 to implement the MVVM pattern. For notification/confirmation dialogues I am using InteractionRequest and InteractionRequest as detailed on the Advanced MVVM Scenarios Using the Prism Library page on msdn. My question is how can I start using OpenFileDialog within MVVM. Prism doesn't provide something similar for Save and Open dialogues. Can you please give me an example of the code that should be incorporated in the View & ViewModel. Thank you.

like image 409
sophon234 Avatar asked Apr 14 '26 04:04

sophon234


1 Answers

YOU need to simply create a dialog service.

public interface IDialogService
{
    void Show();
}

public class DialogService : IDialogService
{
    public void Show()
    {
        //logic to show your dialogs
    }
}

Make sure to register it with your container:

Conatiner.Register<IDialogService, DialogService>( do you want a singletone?);

Then ask for it in your ctor

public ViewAViewModel(IDialogService ds) { ... }

Now call it whenever you want.