Reputation: 1901
I am trying to use Xamarin Forms Previewer. But it display error as shown in attached image. How can I solve this?
Upvotes: 0
Views: 411
Reputation: 311
If you have code in your xaml to wire the View to the View Model, try disabling the code. In my xaml, I had to do this:
utility:ViewModelFetcher.AutoWireViewModel="True"
to
utility:ViewModelFetcher.AutoWireViewModel="False"
and the previewer worked.
Upvotes: 0
Reputation: 1421
As you can see. It crashes because it cannot resolve your dependency (that you inject with the an Autofac ioc Container). If your dependency is resolved at runtime, you probably have to mock it at "design time" by injecting a different implementation. See http://blog.mzikmund.com/2017/07/checking-for-design-mode-in-xamarin-forms/
public static class DesignTimeHelper
{
public static bool DesignModeOn { get; private set; } = true;
}
public static void TurnOffDesignMode()
{
DesignModeOn = false;
}
}
And you'll have to do something like that on your IOC builder:
if(DesignTimeHelper.DesignModeOn)
builder.Register<INotificationManager, MockNotificationManager>();
else // your real dependency
Upvotes: 1