2013-06-20 27 views
3

在設計器中使用MVVMCross中的可見性轉換器後,出現以下錯誤,使我無法使用Blend在我的UI上工作。有任何想法嗎?MvvmCross在Windows Phone設計器中拋出NullReferenceException

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

回答

2

跨平臺的可視性功能是在一個插件 - 所以它需要一個位的IoC系統的初始化,然後才能使用它。

要使用帶有目前轉換器的設計器,您需要添加少量設計時初始化。

對於BindingEx模塊,我們做到這一點使用:https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.BindingEx.WindowsPhone/MvxDesignTimeChecker.cs#L18

如果你需要設計的可見性插件時的支持,那麼你可以這樣做,通過使用類似的設計時間檢查,然後使用以確保能見度轉換已在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(); 

注:顯然這是一個有點哈克 - 很想看到這個拉回項目可用於所有。

+0

也跟進https://github.com/slodge/MvvmCross/issues/323 - 請在其中添加評論/祝福/改進 – Stuart

相關問題