Windows phone MvvmCross在Windows Phone Designer中引发NullReferenceException

Windows phone MvvmCross在Windows Phone Designer中引发NullReferenceException,windows-phone,nullreferenceexception,designer,mvvmcross,Windows Phone,Nullreferenceexception,Designer,Mvvmcross,在设计器中使用MVVMCross的可见性转换器后,我遇到以下错误,阻止我使用Blend处理UI。有什么想法吗 NullReferenceException: Object reference not set to an instance of an object. at Cirrious.CrossCore.Mvx.Resolve[TService]() at Cirrious.MvvmCross.Plugins.Visibility.MvxBaseVisibilityValueConvert

在设计器中使用MVVMCross的可见性转换器后,我遇到以下错误,阻止我使用Blend处理UI。有什么想法吗

NullReferenceException: Object reference not set to an instance of an object.

at Cirrious.CrossCore.Mvx.Resolve[TService]()
at Cirrious.MvvmCross.Plugins.Visibility.MvxBaseVisibilityValueConverter.Convert(Object value, Type targetType, Object parameter, CultureInfo culture)
at Cirrious.CrossCore.WindowsPhone.Converters.MvxNativeValueConverter.Convert(Object value, Type targetType, Object parameter, CultureInfo culture)
at System.Windows.Data.BindingExpression.ConvertToTarget(Object value)
at System.Windows.Data.BindingExpression.GetValue(DependencyObject d, DependencyProperty dp)
at System.Windows.DependencyObject.EvaluateExpression(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry)
at System.Windows.DependencyObject.EvaluateBaseValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
at System.Windows.DependencyObject.EvaluateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry newEntry, ValueOperation operation)
at System.Windows.DependencyObject.UpdateEffectiveValue(DependencyProperty property, EffectiveValueEntry oldEntry, EffectiveValueEntry& newEntry, ValueOperation operation)
at System.Windows.DependencyObject.RefreshExpression(DependencyProperty dp)
at System.Windows.Data.BindingExpression.SendDataToTarget()
at System.Windows.Data.BindingExpression.SourceAcquired()
at System.Windows.Data.BindingExpression.System.Windows.IDataContextChangedListener.OnDataContextChanged(Object sender, DataContextChangedEventArgs e)
at System.Windows.Data.BindingExpression.DataContextChanged(Object sender, DataContextChangedEventArgs e)
at System.Windows.FrameworkElement.OnDataContextChanged(DataContextChangedEventArgs e)
at System.Windows.FrameworkElement.OnAncestorDataContextChanged(DataContextChangedEventArgs e)
at System.Windows.FrameworkElement.NotifyDataContextChanged(DataContextChangedEventArgs e)
at System.Windows.FrameworkElement.OnTreeParentUpdated(DependencyObject newParent, Boolean bIsNewParentAlive)
at System.Windows.DependencyObject.UpdateTreeParent(IManagedPeer oldParent, IManagedPeer newParent, Boolean bIsNewParentAlive, Boolean keepReferenceToParent)
at MS.Internal.FrameworkCallbacks.ManagedPeerTreeUpdate(IntPtr oldParentElement, IntPtr parentElement, IntPtr childElement, Byte bIsParentAlive, Byte bKeepReferenceToParent, Byte bCanCreateParent)
谢谢,
MagooChris

跨平台可视性功能是一个插件,因此在使用之前需要对IoC系统进行一些初始化

要将设计器与转换器一起使用,您需要添加少量的设计时初始化

对于BindingEx模块,我们使用以下方法执行此操作:

如果您需要可见性插件的设计时支持,则可以使用类似的设计时检查,然后使用该检查确保可见性转换已向IoC注册-例如,对于windowsphone,您可以将类似的内容插入到静态资源中:

if (!DesignerProperties.IsInDesignTool)
  return;

if (MvxSingleton<IMvxIoCProvider>.Instance == null)
{
  var iocProvider = MvxSimpleIoCContainer.Initialize();
  Mvx.RegisterSingleton(iocProvider);
}

var forceVisibility = new Cirrious.MvvmCross.Plugins.Visibility.WindowsPhone.Plugin();
forceVisibility.Load();
if(!DesignerProperties.IsInDesignTool)
返回;
if(MvxSingleton.Instance==null)
{
var iocProvider=MvxSimpleIoCContainer.Initialize();
Mvx.RegisterSingleton(iocProvider);
}
var forceVisibility=new cirrian.MvvmCross.Plugins.Visibility.WindowsPhone.Plugin();
forceVisibility.Load();
注意:显然这有点不成熟-希望看到这一点被重新纳入到项目中,以供所有人使用。

也会跟进-请在此处添加评论/愿望/改进