MvvmCross, UWP, MessengerPlugin: Failed to load page

Problem : when I added the IMvxMessanger DI constructor to the ViewModel, I got the error: "The page could not load"; If I remove this DI, my tool works fine. Btw, IHelloService will not give this error, it only works fine without IMvxMessanger.

I followed this guide: https://mvvmcross.com/docs/a-windows-universal-app-platform-project

MvvmCross Version: 4.4.0

Code Examples:

Firstviewmodel

public class FirstViewModel : MvxViewModel
{
    private readonly IHelloService _helloService;
    private readonly IMvxMessenger _messenger;

    public FirstViewModel(IHelloService helloService, IMvxMessenger messenger)
    {
        _helloService = helloService;
        _messenger = messenger;
    }

    private string _hello = "Hello MvvmCross";
    public string Hello
    {
        get { return _hello; }
        set { SetProperty(ref _hello, value); }
    }
}

Firstview.xaml.cs

public sealed partial class FirstView : MvxWindowsPage
{
    public FirstView()
    {
        InitializeComponent();
    }
}

Firstview.xaml

<views:MvxWindowsPage
x:Class="MvvmCrossDocs.UWP.Views.FirstView"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:MvvmCrossDocs.UWP.Views"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:views="using:MvvmCross.WindowsUWP.Views"
mc:Ignorable="d">

<Grid Background="{StaticResource ApplicationPageBackgroundThemeBrush}">
    <StackPanel>
        <TextBox Text="{Binding Hello, Mode=TwoWay}" />
        <TextBlock Text="{Binding Hello}" />
    </StackPanel>
</Grid>

Customization

public class Setup : MvxWindowsSetup
{
    public Setup(Frame rootFrame) : base(rootFrame)
    {
    }

    protected override IMvxApplication CreateApp()
    {
        return new Core.App();
    }
}

Also these are strings in App.xaml.cs

if (rootFrame.Content == null)
{
    var setup = new Setup(rootFrame);
    setup.Initialize();

    var start = Mvx.Resolve<IMvxAppStart>();
    start.Start();
}
+4
source share
1 answer

, , bootstrap MvxMessenger UWP. UWP project.json, Nuget 3. , nuget, .

, bootstrap bootstrap.cs, Setup.cs.

Bootstrap:

MessengerPluginBootstrap.cs

using MvvmCross.Platform.Plugins;

namespace <<YOUR_NAMESSPACE>>.Bootstrap
{
    public class MessengerPluginBootstrap
            : MvxPluginBootstrapAction<MvvmCross.Plugins.Messenger.PluginLoader>
    {
    }
}

Setup.cs :

IMvxMessenger MvxMessengerHub.

protected override void InitializeLastChance()
{
    base.InitializeLastChance();
    Mvx.RegisterSingleton<IMvxMessenger>(new MvxMessengerHub());
}
+1

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


All Articles