Question

I'm getting the following error after using a Visibility Converter from MVVMCross in the designer, stopping me from using Blend to work on my UI. Any Ideas?

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)

Thanks, MagooChris

Was it helpful?

Solution

The cross-platform visibility functionality is in a plugin - so it needs a bit of the IoC system initialised before it can be used.

To use the designer with the converters present you'll need to add a small amount of design-time initialization.

For the BindingEx module we do this using: https://github.com/slodge/MvvmCross/blob/v3/Cirrious/Cirrious.MvvmCross.BindingEx.WindowsPhone/MvxDesignTimeChecker.cs#L18

If you need design time support for the visibility plugin, then you could do this by using a similar design time check and then using that to make sure the visibility conversion is registered with IoC - e.g. for windowsphone you could insert something like this into a static resource:

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();

Note: obviously this is a bit hacky - would love to see this pulled back into the project to be available for all.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top