MessageBox and FilePicker

StyleMVVM provides wrapper services around both the MessageDialog class and FileOpenPicker class to allow for easy use as well as making it possible to Mock the implementations for unit test time (default Faux implementations are provided with the framework but you can chose to write your own as well). Below are examples of how to import and use the services.

IMessageBoxService

    public class SomeViewModel : BaseViewModel
    {
       [Import]
       public IMessageBoxService MessageBoxService { get; set; }

       public async void ClickHandler()
       {
           await MessageBoxService.Show("Hello World");
       }
    } 

IFilePickerService

    public class SomeViewModel : BaseViewModel
    {
       [Import]
       public IFilePickerService FilePicker { get; set; }

       public async void ClickHandler()
       {
           StorageFile storageFile = 
                 await FilePicker.PickFileAsync(PickerLocationId.DocumentsLibrary, ".txt");
       }
    }

Last edited Nov 3, 2012 at 3:52 PM by ipjohnson123, version 4

Comments

No comments yet.