Mvvmcross with Xamarin.Forms

I developed an application based on Xamarin for iOS and Andsroid using mvvmcross. 2 weeks ago Xamarin announced Xamarin.Forms. Has anyone succeeded in porting Hamarin using mvvmcross to Camarin.Forms with mvvmcross? I want to reuse most of my code, I use: Messenger, Location, SQLite, etc.

It would be great if someone could provide a .sln sample with the integration of Xamarin.Forms and mvvmcross. I think mvvmcross developers are working on publishing another video (# 43?) About this issue, but I'm not sure about that.

Thanks in advanced

+4
source share
2 answers

Cheesebaron .

, Ninja Coder VS Extension, Xam.Forms + MvvmCross .

Cheesebaron. ContentPages ( , ). MvvmCross Messenger PlugIn. , , , ..

Cheesebaron MvxPresenterHelper ViewModels ContentPages. IoC MvvmCross (Mvx) , .

Helper IQ MvvmCross. . , , , .

MvxPresenterHelper.cs

public static ContentPage CreatePage(MvxViewModelRequest request)
    {
        var viewModelName = request.ViewModelType.Name;
        var pageName = viewModelName.Replace("ViewModel", "Page");
        Type pageType = Type.GetType(App.PageNamespace + "." + pageName);

        if (pageType == null)
        {
            Mvx.Trace("Page not found for {0}", pageName);
            return null;
        }

        var page = Mvx.Resolve(pageType) as ContentPage;

        if (page == null)
        {
            Mvx.Error("Failed to create ContentPage {0}", pageName);
        }
        return page;
    }

App.PageNamespace. ContentPages.

App.cs

public class App : MvxApplication
{
    public static string PageNamespace { get; private set; }

    public App()
    {
        PageNamespace = this.GetType().Namespace + ".Pages";
    }
    public override void Initialize()
    {
        // Mvx default registration here

        // Register all ContentPages
        this.CreatableTypes()
            .EndingWith("Page")
            .InNamespace(PageNamespace)
            .AsTypes()
            .RegisterAsDynamic();

        this.RegisterAppStart<MainViewModel>();
    }
}
+1

Source: https://habr.com/ru/post/1544221/


All Articles