gpt4 book ai didi

windows-phone - MvvmCross 在 Windows Phone 设计器中抛出 NullReferenceException

转载 作者:行者123 更新时间:2023-12-04 16:04:33 25 4
gpt4 key购买 nike

在设计器中使用来自 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)

谢谢,马古克里斯

最佳答案

跨平台可见性功能在插件中 - 因此在使用之前需要初始化一些 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();

注意:显然这有点 hacky - 希望看到它被拉回到项目中以供所有人使用。

关于windows-phone - MvvmCross 在 Windows Phone 设计器中抛出 NullReferenceException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17207058/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com