open SaveFileDialog [closed]

If you are using a framework like MVVM Light, you can send a message from your callback to your UI thread (passing your parameters required for saving).

EDIT. Adding example

In your code behind page most likely, you will need to setup a listener for the custom message we will send. Its good practice to do this in your onload or onnavigateto methods. I’ll assume that your callback will load up a custom object called CustomObjectWithParams that you are getting from db.

In your xaml code behind:

protected override void OnNavigatedTo(NavigationEventArgs e)
    {
        // the "MyViewModel.OpenSaveDialogRequest" can be any string.. it just needs to synch up with what was sent from the viewmodel below
        Messenger.Default.Register<CustomObjectWithParams>(this, "MyViewModel.OpenSaveDialogRequest", objParams => ShowSaveDialog(objParams));
        base.OnNavigatedTo(e);
    }

    private void ShowSaveDialog(CustomObjectWithParams obj) {
        // do your  open save here in the UI thread
    }

    // be smart, make sure you unregister this listener when you navigate away!
    protected override void OnNavigatedFrom(NavigationEventArgs e)
    {

        Messenger.Default.Unregister<CustomObjectWithParams>(this);
        base.OnNavigatedFrom(e);
    }

Now in your view model callback function (not running on UI thread right)… you want to send the params you are getting asynch. You can do this as so:

protected void your_asynch_callbackfunction(your args) {
            CustomObjectWithParams objParams = new CustomObjectWithParams();
            // fill up this object here....

            // now send the object to the UI to do something with it
            Messenger.Default.Send<CustomObjectWithParams>(objParams, "MyViewModel.OpenSaveDialogRequest");

        }

Leave a Comment