Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MvvmCross: How to navigate to something besides a ViewModel?

What would I put in my MvxCommand to navigate to a simple URL? All mobile platforms have a mechanism to ask the OS for an Activity or ViewController that can display the contents of a URL. How would I do that with MvvmCross? One way that I know of is to put special stuff in the presentationBundle and/or parameterBundle when calling ShowViewModel that the presenter can detect to do the special OpenUrl command. But is that the best way??

like image 804
user2395286 Avatar asked Oct 22 '22 09:10

user2395286


1 Answers

There is a plugin which enables this - https://github.com/slodge/MvvmCross/tree/v3/Plugins/Cirrious/WebBrowser

If that plugins is loaded, then a viewmodel can use:

public class MyViewModel : MvxViewModel
{
    private readonly IMvxWebBrowserTask _webBrowser;

    public MyViewModel(IMvxWebBrowserTask webBrowser)
    {
       _webBrowser = webBrowse;
    }

    public ICommand ShowWebPage
    {
        get { return new MvxCommand(() => _webBrowser.ShowWebPage("https://github.com/slodge/mvvmcross");
    }
}

You can see this used in, for example:

  • https://github.com/slodge/MvvmCross-Tutorials/blob/master/Sample%20-%20CirriousConference/Cirrious.Conference.Core/ViewModels/BaseViewModel.cs
  • https://github.com/slodge/MvvmCross-Tutorials/blob/master/Sample%20-%20CustomerManagement/CustomerManagement/CustomerManagement/ViewModels/DetailsCustomerViewModel.cs

If you ever need to create your own plugins, see https://speakerdeck.com/cirrious/plugins-in-mvvmcross

like image 115
Stuart Avatar answered Nov 16 '22 23:11

Stuart