After updating my project to Unified API and MVVM Cross 3.5 stable ,I am getting the following warring message in the console for all button bindings...
I am binding like this.
try {
this.AddBindings(
new Dictionary < object, string > () {
//all the command controls - such as buttons
{
btnXmit,
"TouchUpInside cmdXmitClicked"
}, {
btnCancel,
"TouchUpInside cmdBack"
},
});
} catch (Exception error) {
}
at
Cirrious.CrossCore.WeakSubscription.MvxWeakEventSubscription2[System.Windows.Input.ICommand,System.EventArgs]..ctor (ICommand source, System.Reflection.EventInfo sourceEventInfo, System.EventHandler1 targetEventHandler) [0x00028] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/CrossCore/Cirrious.CrossCore/WeakSubscription/MvxWeakEventSubscription.cs:52
at Cirrious.CrossCore.WeakSubscription.MvxCanExecuteChangedEventSubscription..ctor (ICommand source, System.EventHandler1 eventHandler) [0x00000] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/CrossCore/Cirrious.CrossCore/WeakSubscription/MvxCanExecuteChangedEventSubscription.cs:21
at Cirrious.CrossCore.WeakSubscription.MvxWeakSubscriptionExtensionMethods.WeakSubscribe (ICommand source, System.EventHandler1 eventHandler) [0x00003] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/CrossCore/Cirrious.CrossCore/WeakSubscription/MvxWeakSubscriptionExtensionMethods.cs:68
at Cirrious.MvvmCross.Binding.Touch.Target.MvxUIControlTouchUpInsideTargetBinding.SetValueImpl (System.Object target, System.Object value) [0x00045] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/Cirrious/Cirrious.MvvmCross.Binding.Touch/Target/MvxUIControlTouchUpInsideTargetBinding.cs:74
at Cirrious.MvvmCross.Binding.Bindings.Target.MvxConvertingTargetBinding.SetValue (System.Object value) [0x000bd] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/Cirrious/Cirrious.MvvmCross.Binding/Bindings/Target/MvxConvertingTargetBinding.cs:64
at Cirrious.MvvmCross.Binding.Bindings.MvxFullBinding.UpdateTargetFromSource (System.Object value) [0x00036] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/Cirrious/Cirrious.MvvmCross.Binding/Bindings/MvxFullBinding.cs:162
2015-02-16 17:48:14.433 RemoteInspectioniOS[3506:119564] MvxBind: Error: 212.37 Problem seen during binding execution for binding TouchUpInside for cmdBack - problem ArgumentNullException: missing source event info in MvxWeakEventSubscription
Parameter name: sourceEventInfo
at Cirrious.CrossCore.WeakSubscription.MvxWeakEventSubscription2[System.Windows.Input.ICommand,System.EventArgs]..ctor (ICommand source, System.Reflection.EventInfo sourceEventInfo, System.EventHandler1 targetEventHandler) [0x00028] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/CrossCore/Cirrious.CrossCore/WeakSubscription/MvxWeakEventSubscription.cs:52
at Cirrious.CrossCore.WeakSubscription.MvxCanExecuteChangedEventSubscription..ctor (ICommand source, System.EventHandler1 eventHandler) [0x00000] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/CrossCore/Cirrious.CrossCore/WeakSubscription/MvxCanExecuteChangedEventSubscription.cs:21
at Cirrious.CrossCore.WeakSubscription.MvxWeakSubscriptionExtensionMethods.WeakSubscribe (ICommand source, System.EventHandler1 eventHandler) [0x00003] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/CrossCore/Cirrious.CrossCore/WeakSubscription/MvxWeakSubscriptionExtensionMethods.cs:68
at Cirrious.MvvmCross.Binding.Touch.Target.MvxUIControlTouchUpInsideTargetBinding.SetValueImpl (System.Object target, System.Object value) [0x00045] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/Cirrious/Cirrious.MvvmCross.Binding.Touch/Target/MvxUIControlTouchUpInsideTargetBinding.cs:74
at Cirrious.MvvmCross.Binding.Bindings.Target.MvxConvertingTargetBinding.SetValue (System.Object value) [0x000bd] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/Cirrious/Cirrious.MvvmCross.Binding/Bindings/Target/MvxConvertingTargetBinding.cs:64
at Cirrious.MvvmCross.Binding.Bindings.MvxFullBinding.UpdateTargetFromSource (System.Object value) [0x00036] in /Volumes/WORKSPACE/Workspace/V3.5/framework/framework/MvvmCross-3/Cirrious/Cirrious.MvvmCross.Binding/Bindings/MvxFullBinding.cs:162
You'll need to create a LinkerPleaseInclude.cs file with the following code:
public class LinkerPleaseInclude
{
public void Include(ICommand command)
{
command.CanExecuteChanged += (s, e) => { if (command.CanExecute(null)) command.Execute(null); };
}
}
EDIT (per my comment):
Related
I have tried a lot of combination to test the code in LoadData function.
The first time the Page loaded, the LoadData function got called. Later user change the date which causing the LoadData function to be called again. This time there was an error quoted below. If I commented the Collection = programs line, the code have no problem.
The problem even if the programs has 0 item in the second execution of the function.
public async Task LoadData (DateTime day)
{
this.day = day;
var programs = await new ECEProgramLogic().GetGrouppedProgram(day.Date, actionNameType);
Collection = programs;
}
private ObservableCollection<GroupViewModel<object>> collection;
public ObservableCollection<GroupViewModel<object>> Collection
{
get
{
return collection;
}
set
{
collection = value;
Banner = new NoDataBannerViewModel<GroupViewModel<object>>(value, AppResources.NoDataToShow);
OnPropertyChanged(nameof(Collection));
}
}
Specified argument was out of the range of valid values. Parameter
name: index
Stacktrace from Xamarin:
at Xamarin.Forms.ListProxy.get_Item (System.Int32 index) [0x0000b] in D:\agent_work\1\s\Xamarin.Forms.Core\ListProxy.cs:127
at Xamarin.Forms.ListProxy.System.Collections.IList.get_Item (System.Int32 index) [0x00000] in D:\agent_work\1\s\Xamarin.Forms.Core\ListProxy.cs:444
at Xamarin.Forms.Internals.TemplatedItemsList2[TView,TItem].get_Item (System.Int32 index) [0x00008] in <afec569c85894ae9a18371a2fecd2d37>:0
at Xamarin.Forms.Platform.iOS.ListViewRenderer+ListViewDataSource.HeaderViewDisplayingEnded (UIKit.UITableView tableView, UIKit.UIView headerView, System.nint section) [0x0001f] in <82f6100a289642ae988dc0d85a373bef>:0
at (wrapper managed-to-native) ObjCRuntime.Messaging.void_objc_msgSend(intptr,intptr)
at UIKit.UITableView.ReloadData () [0x00008] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.9.1.24/src/Xamarin.iOS/UIKit/UITableView.g.cs:792
at Xamarin.Forms.Platform.iOS.ListViewRenderer.UpdateItems (System.Collections.Specialized.NotifyCollectionChangedEventArgs e, System.Int32 section, System.Boolean resetWhenGrouped) [0x002b8] in <82f6100a289642ae988dc0d85a373bef>:0
at Xamarin.Forms.Platform.iOS.ListViewRenderer.OnCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00000] in <82f6100a289642ae988dc0d85a373bef>:0
at Xamarin.Forms.Internals.TemplatedItemsList2[TView,TItem].OnCollectionChanged (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x0000a] in :0
at Xamarin.Forms.Internals.TemplatedItemsList2[TView,TItem].GroupedReset () [0x000b6] in <afec569c85894ae9a18371a2fecd2d37>:0
at Xamarin.Forms.Internals.TemplatedItemsList2[TView,TItem].OnCollectionChangedGrouped (System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00459] in :0
at Xamarin.Forms.Internals.TemplatedItemsList2[TView,TItem].OnProxyCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e, System.Boolean fixWindows) [0x00008] in <afec569c85894ae9a18371a2fecd2d37>:0
at Xamarin.Forms.Internals.TemplatedItemsList2[TView,TItem].OnProxyCollectionChanged (System.Object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e) [0x00000] in :0
at Xamarin.Forms.Internals.TemplatedItemsList2[TView,TItem].OnItemsSourceChanged (System.Boolean fromGrouping) [0x00069] in <afec569c85894ae9a18371a2fecd2d37>:0
at Xamarin.Forms.Internals.TemplatedItemsList2[TView,TItem].BindableOnPropertyChanged (System.Object sender, System.ComponentModel.PropertyChangedEventArgs e) [0x00020] in :0
at (wrapper delegate-invoke) .invoke_void_object_PropertyChangedEventArgs(object,System.ComponentModel.PropertyChangedEventArgs)
at Xamarin.Forms.BindableObject.OnPropertyChanged (System.String propertyName) [0x0000a] in D:\agent_work\1\s\Xamarin.Forms.Core\BindableObject.cs:146
at Xamarin.Forms.Element.OnPropertyChanged (System.String propertyName) [0x00000] in D:\agent_work\1\s\Xamarin.Forms.Core\Element.cs:401
at Xamarin.Forms.BindableObject.SetValueActual (Xamarin.Forms.BindableProperty property, Xamarin.Forms.BindableObject+BindablePropertyContext context, System.Object value, System.Boolean currentlyApplying, Xamarin.Forms.Internals.SetValueFlags attributes, System.Boolean silent) [0x00107] in D:\agent_work\1\s\Xamarin.Forms.Core\BindableObject.cs:602
at Xamarin.Forms.BindableObject.SetValueCore (Xamarin.Forms.BindableProperty property, System.Object value, Xamarin.Forms.Internals.SetValueFlags attributes, Xamarin.Forms.BindableObject+SetValuePrivateFlags privateAttributes) [0x0015b] in D:\agent_work\1\s\Xamarin.Forms.Core\BindableObject.cs:399
at Xamarin.Forms.BindingExpression.ApplyCore (System.Object sourceObject, Xamarin.Forms.BindableObject target, Xamarin.Forms.BindableProperty property, System.Boolean fromTarget) [0x001f9] in D:\agent_work\1\s\Xamarin.Forms.Core\BindingExpression.cs:172
at Xamarin.Forms.BindingExpression.Apply (System.Boolean fromTarget) [0x0003e] in D:\agent_work\1\s\Xamarin.Forms.Core\BindingExpression.cs:56
at Xamarin.Forms.BindingExpression+BindingExpressionPart.b__47_0 () [0x00000] in D:\agent_work\1\s\Xamarin.Forms.Core\BindingExpression.cs:557
at Foundation.NSAsyncActionDispatcher.Apply () [0x00000] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.9.1.24/src/Xamarin.iOS/Foundation/NSAction.cs:163
at (wrapper managed-to-native) UIKit.UIApplication.UIApplicationMain(int,string[],intptr,intptr)
at UIKit.UIApplication.Main (System.String[] args, System.IntPtr principal, System.IntPtr delegate) [0x00005] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.9.1.24/src/Xamarin.iOS/UIKit/UIApplication.cs:79
at UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x00038] in /Library/Frameworks/Xamarin.iOS.framework/Versions/11.9.1.24/src/Xamarin.iOS/UIKit/UIApplication.cs:63
at Tux.iOS.Application.Main (System.String[] args) [0x00001] in /Users/simon/Documents/AimyPlus/EceAdmin/Tux/Tux.iOS/Main.cs:17
> Xamarin.Android
Version: 8.2.0.16 (Visual Studio Community)
Android SDK: /Users/simon/Library/Developer/Xamarin/android-sdk-macosx
Supported Android versions:
6.0 (API level 23)
7.1 (API level 25)
8.0 (API level 26)
SDK Tools Version: 25.2.5
SDK Platform Tools Version: 25.0.5
SDK Build Tools Version: 25.0.3
Java SDK: /usr
java version "1.8.0_101"
Java(TM) SE Runtime Environment (build 1.8.0_101-b13)
Java HotSpot(TM) 64-Bit Server VM (build 25.101-b13, mixed mode)
Android Designer EPL code available here:
https://github.com/xamarin/AndroidDesigner.EPL
Xamarin Inspector
Version: 1.4.0
Hash: b3f92f9
Branch: master
Build date: Fri, 19 Jan 2018 22:00:34 GMT
Client compatibility: 1
Apple Developer Tools
Xcode 9.2 (13772)
Build 9C40b
Xamarin.Mac
Version: 4.2.1.28 (Visual Studio Community)
Xamarin.iOS
Version: 11.9.1.24 (Visual Studio Community)
Hash: f62de472
Branch: xcode9.3
Build date: 2018-03-29 19:30:53-0400
It was an issue of the updated Xamarin.Forms 2.51444934. It happened when doing a groupped listview. In order to solve:
ListView.HasUnevenRows = false;
ListView.IsGroupingEnabled = false;
((ObservableCollection<T>)listView.ItemsSource).Clear();
ListView.HasUnevenRows = true;
ListView.IsGroupingEnabled = true;
Put similar code before replacing new data collection. The problem will be solved.
Adding those lines to listview properties works for me.
IsGroupingEnabled="false"
CachingStrategy="RecycleElement"
Hi, my android application sometimes stucks on startup. On Xamarin test cloud the failure seems like;
SetUp : System.TimeoutException : Timed out waiting...
at Xamarin.UITest.Shared.WaitForHelper.WaitFor (System.Func1 predicate, System.String timeoutMessage, Nullable1 timeout, Nullable1 retryFrequency, Nullable1 postTimeout) <0x7e4c998 + 0x004db> in :0
at Xamarin.UITest.Android.AndroidApp..ctor (IAndroidAppConfiguration appConfiguration) <0x7cacab8 + 0x0073b> in :0
at Xamarin.UITest.Configuration.AndroidAppConfigurator.StartApp (AppDataMode appDataMode) <0x7cac008 + 0x00063> in :0
at YH.MB.Test.AppInitializer.StartApp (Platform platform) <0x7cab060 + 0x00027> in :0
at YH.MB.Test.Tests.BeforeEachTest () <0x7cab010 + 0x00013> in :0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) <0x3249110 + 0x00093> in :0
When i tried it on Samsung s3(on xamarin test cloud) there was a StackTrace too;
java.lang.NullPointerException: key == null
at android.util.LruCache.get(LruCache.java: 113)
at com.android.providers.settings.SettingsProvider$SettingsCache.isRedundantSetValue(SettingsProvider.java: 872)
at com.android.providers.settings.SettingsProvider.insert(SettingsProvider.java: 574)
at android.content.ContentProvider$Transport.insert(ContentProvider.java: 201)
at android.content.ContentProviderNative.onTransact(ContentProviderNative.java: 148)
at android.os.Binder.execTransact(Binder.java: 367)
at dalvik.system.NativeStart.run(Native Method: )
I can not repeat that issue on debug mode. What can it be?
My Android OnCreate method is;
protected override void OnCreate(Bundle bundle)
{
// set the layout resources first
ToolbarResource = Resource.Layout.toolbar;
TabLayoutResource = Resource.Layout.tabs;
base.OnCreate(bundle);
Forms.Init(this, bundle);
#if ENABLE_TEST_CLOUD
Xamarin.Forms.Forms.ViewInitialized += (object sender, Xamarin.Forms.ViewInitializedEventArgs e) =>
{
if (!string.IsNullOrWhiteSpace(e.View.AutomationId))
{
e.NativeView.ContentDescription = e.View.AutomationId;
}
};
#endif
var container = new SimpleContainer();
container.Register<IDevice>(t => AndroidDevice.CurrentDevice);
container.Register<IDisplay>(t => t.Resolve<IDevice>().Display);
container.Register<IMediaPicker>(t => new MediaPicker());
container.Register<IFontManager>(t => new FontManager(t.Resolve<IDisplay>()));
container.Register<INetwork>(t => t.Resolve<IDevice>().Network);
container.Register<IJsonSerializer, MBJsonSerializer>();
container.Register<IPhoneService, PhoneService>();
container.Register<IUserDialogs>(t => UserDialogs.Instance);
if (!Resolver.IsSet)
Resolver.SetResolver(container.GetResolver());
UserDialogs.Init(this);
LoadApplication(new App());
}
public override void OnRequestPermissionsResult(int requestCode, string[] permissions, Permission[] grantResults)
{
PermissionsImplementation.Current.OnRequestPermissionsResult(requestCode, permissions, grantResults);
}
My UITest SetUp Method ;
[TestFixture(Platform.Android)]
[TestFixture(Platform.iOS)]
public class Tests
{
IApp app;
Platform platform;
public Tests(Platform platform)
{
this.platform = platform;
}
[SetUp]
public void BeforeEachTest()
{
app = AppInitializer.StartApp(platform);
}
}
Thanks in advance.
I'm currently using MvvmCross for new app projects, and I'm trying to display a header view with a MvxListView. Reading discussions such as this has led me to understand that a headerview cannot be added after the adapter has been set, so the constructor must be overridden so that the header is added before the MvxAdapter is set. This has led me to implement the following class:
public class HeaderListView : MvxListView
{
public FrameLayout HeaderFrame { get; set; }
public HeaderListView(Context context, IAttributeSet attrs)
: this(context, attrs, new MvxAdapter(context))
{
}
public HeaderListView(Context context, IAttributeSet attrs, IMvxAdapter adapter)
: base(context, attrs, null)
{
InitializeHeader(context);
// Note: Any calling derived class passing a null adapter is responsible for setting
// it's own itemTemplateId
if (adapter == null)
return;
var itemTemplateId = MvxAttributeHelpers.ReadListItemTemplateId(context, attrs);
adapter.ItemTemplateId = itemTemplateId;
Adapter = adapter;
}
private void InitializeHeader(Context context)
{
HeaderFrame = new FrameLayout(context);
AddHeaderView(HeaderFrame);
}
}
Pay particular attention to the InitializeHeader call in the second constructor. When I comment this line out, the test application starts up fine and this HeaderListView behaves indistinguishably from a standard MvxListView. However, uncomment that line and you are greeted with a blank ListView and a number of binding errors:
MvxBind:Error: 10.86 Problem seen during binding execution for binding ItemsSource for Names - problem TargetInvocationException: Exception has been thrown by the target of an invocation.
02-02 23:33:01.948 I/mono-stdout( 2323): MvxBind:Error: 10.86 Problem seen during binding execution for binding ItemsSource for Names - problem TargetInvocationException: Exception has been thrown by the target of an invocation.
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Binding.Bindings.Target.MvxPropertyInfoTargetBinding.SetValueImpl (System.Object target, System.Object value) [0x00000] in <filename unknown>:0
02-02 23:33:01.948 I/mono-stdout( 2323): at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
02-02 23:33:01.948 I/mono-stdout( 2323): at System.Reflection.MethodBase.Invoke (System.Object obj, System.Object[] parameters) [0x00000] in <filename unknown>:0
02-02 23:33:01.958 I/mono-stdout( 2323): at Cirrious.MvvmCross.Binding.Bindings.Target.MvxPropertyInfoTargetBinding.SetValueImpl (System.Object target, System.Object value) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Binding.Bindings.Target.MvxConvertingTargetBinding.SetValue (System.Object value) [0x00000] in <filename unknown>:0
at Cirrious.MvvmCross.Binding.Bindings.MvxFullBinding.UpdateTargetFromSource (System.Object value) [0x00000] in <filename unknown>:0
InnerException was NullReferenceException: Object reference not set to an instance of an object
at Cirrious.MvvmCross.Binding.Droid.Views.MvxListView.set_ItemsSource (IEnumerable value) [0x00000] in <filename unknown>:0
at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
02-02 23:33:01.958 I/mono-stdout( 2323): at Cirrious.MvvmCross.Binding.Bindings.Target.MvxConvertingTargetBinding.SetValue (System.Object value) [0x00000] in <filename unknown>:0
02-02 23:33:01.968 I/mono-stdout( 2323): at Cirrious.MvvmCross.Binding.Bindings.MvxFullBinding.UpdateTargetFromSource (System.Object value) [0x00000] in <filename unknown>:0
02-02 23:33:01.968 I/mono-stdout( 2323): InnerException was NullReferenceException: Object reference not set to an instance of an object
02-02 23:33:01.968 I/mono-stdout( 2323): at Cirrious.MvvmCross.Binding.Droid.Views.MvxListView.set_ItemsSource (IEnumerable value) [0x00000] in <filename unknown>:0
02-02 23:33:01.968 I/mono-stdout( 2323): at (wrapper managed-to-native) System.Reflection.MonoMethod:InternalInvoke (System.Reflection.MonoMethod,object,object[],System.Exception&)
at System.Reflection.MonoMethod.Invoke (System.Object obj, BindingFlags invokeAttr, System.Reflection.Binder binder, System.Object[] parameters, System.Globalization.CultureInfo culture) [0x00000] in <filename unknown>:0
I can't make any sense at all of this error, because the only difference that causes its appearance is that I assign a header view before assigning the adapter, but that has nothing whatsoever to do with the adapter. What is the source of this error, and how can I work around it?
The full source of my sample project demonstrating this problem is available on github.
The reason has to do with the hacky way that headers and footers were added to ListView. When you add a header or footer to a ListView, when you set the adapter for the list view, it wraps your adapter in a HeaderViewListAdapter that returns the headers and footers as though they were just rows before and after the actual rows your adapter returns.
The reason this fails with MvxListView is its Adpater property which looks like this:
public new IMvxAdapter Adapter
{
get { return base.Adapter as IMvxAdapter; }
set
{
// Code to copy ItemsSource and template ID
base.Adapter = value;
}
}
It does not store the IMvxAdapter instance you give it. It just sets it in the base.Adapter and expects when it gets base.Adapter later it will be the same value it set earlier. But that is not true when headers and footers are added to the list. The class you get back from base.Adapter will be a HeaderViewListAdapter that wraps the instance of IMvxAdapter that was set earlier.
There is no good way to work around this as a user of MvxList (other than copy and change MvxList). The fix for Stuart would be to not rely on base.Adapter for the getter, but instead store the value into a field in the setter and return that from the getter.
By adding ItemsSource in the .axml file causes the List to set an Adapter and you can not add a header/footer to a listview when an Adapter is set.
I had a similar issue and ended using
MvxListWithHeader - It allows you to add a header and footer to a MvxListView.
I can't see any obvious reason behind the error.
It doesn't look like the "binding process" is being disrupted from your trace. Instead it looks like the Adapter is somehow being stuck at null.
One suggestion to help debug further - if you add a new ItemsSource to your custom list view, then this will be used for binding - and will give you a place to put a breakpoint so that you can investigate the state of the ListView control during the set_ItemsSource null reference problem.
[MvxSetToNullAfterBinding]
public new IEnumerable ItemsSource
{
get { return Adapter.ItemsSource; }
set {
// here is where null is being reported
// add a breakpoint and examine Adapter and ((ListView)this).Adapter in the watch window
Adapter.ItemsSource = value;
}
}
Beyond this, you could try copying all the MvxListView code into your view to see if that helps identify the issue.
I use MvvmCross for develop a CrossPlatform App.
I work on my Mac and I have not errors when I build my solution.
When I run it... I have this error : failed to find constructor for type Cirrious.MvvmCross.ViewModels.MvxViewModelLoader and highlights base.ViewDidLoad();
Code :
public partial class MainView : MvxViewController
{
static bool UserInterfaceIdiomIsPhone {
get { return UIDevice.CurrentDevice.UserInterfaceIdiom == UIUserInterfaceIdiom.Phone; }
}
public MainView ()
: base (UserInterfaceIdiomIsPhone ? "MainView_iPhone" : "MainView_iPad", null)
{
}
public override void DidReceiveMemoryWarning ()
{
// Releases the view if it doesn't have a superview.
base.DidReceiveMemoryWarning ();
// Release any cached data, images, etc that aren't in use.
}
public override void ViewDidLoad ()
{
base.ViewDidLoad ();
// Perform any additional setup after loading the view, typically from a nib.
}
It's a default code, I just changed super-class (UIViewController to MvxViewController)
Stacktrace :
Failed to find constructor for type Cirrious.MvvmCross.ViewModels.MvxViewModelLoader
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.IoCConstruct (System.Type type) [0x00000] in :0
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer+ConstructingResolver.Resolve () [0x00000] in :0
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.InternalTryResolve (System.Type type, ResolveOptions resolveOptions, System.Object& resolved) [0x00000] in :0
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.InternalTryResolve (System.Type type, System.Object& resolved) [0x00000] in :0
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.Resolve (System.Type t) [0x00000] in :0
at Cirrious.CrossCore.IoC.MvxSimpleIoCContainer.Resolve[IMvxViewModelLoader] () [0x00000] in :0
at Cirrious.CrossCore.Mvx.Resolve[IMvxViewModelLoader] () [0x00000] in :0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods.LoadViewModel (IMvxTouchView touchView) [0x00000] in :0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods+<>c_DisplayClass1.b_0 () [0x00000] in :0
at Cirrious.MvvmCross.Views.MvxViewExtensionMethods.OnViewCreate (IMvxView view, System.Func`1 viewModelLoader) [0x00000] in :0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerExtensionMethods.OnViewCreate (IMvxTouchView touchView) [0x00000] in :0
at Cirrious.MvvmCross.Touch.Views.MvxViewControllerAdapter.HandleViewDidLoadCalled (System.Object sender, System.EventArgs e) [0x00000] in :0
at (wrapper delegate-invoke) :invoke_void_this__object_EventArgs (object,System.EventArgs)
at Cirrious.CrossCore.Core.MvxDelegateExtensionMethods.Raise (System.EventHandler eventHandler, System.Object sender) [0x00000] in :0
at Cirrious.CrossCore.Touch.Views.MvxEventSourceViewController.ViewDidLoad () [0x00000] in :0
at TrainingCatalog.Touch.MainView.ViewDidLoad () [0x00002] in /Users/a_masteruser/Projects/DefaultCollection/_git/HapplyTrainingCatalog/TrainingCatalog.Touch/Views/MainView.cs:30
at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend (intptr,intptr)
at MonoTouch.UIKit.UIWindow.MakeKeyAndVisible () [0x00008] in /Developer/MonoTouch/Source/monotouch/src/UIKit/.pp-UIWindow.g.cs:129
at TrainingCatalog.Touch.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x0003c] in /Users/a_masteruser/Projects/DefaultCollection/_git/HapplyTrainingCatalog/TrainingCatalog.Touch/AppDelegate.cs:21
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr)
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004c] in /Developer/MonoTouch/Source/monotouch/src/UIKit/.pp-UIApplication.cs:38
at TrainingCatalog.Touch.Application.Main (System.String[] args) [0x00008] in /Users/a_masteruser/Projects/DefaultCollection/_git/HapplyTrainingCatalog/TrainingCatalog.Touch/Main.cs:17
Failed to find constructor for type Cirrious.MvvmCross.ViewModels.MvxViewModelLoader
From the stack trace, I'm guessing the line that is failing is: https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross.Touch/Views/MvxViewControllerExtensionMethods.cs#L44
This is looking in IoC for a type which has been registered in setup as:
protected virtual void InitializeViewModelFramework()
{
Mvx.RegisterType<IMvxViewModelLoader, MvxViewModelLoader>();
}
(from https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross/Platform/MvxSetup.cs#L192)
Looking at MvxViewModelLoader, this is defined in: https://github.com/MvvmCross/MvvmCross/blob/v3.1/Cirrious/Cirrious.MvvmCross/ViewModels/MvxViewModelLoader.cs - so it should have a default public parameterless constructor added by the compiler...
With this in mind...
I'm guessing that maybe Xamarin is stripping out the constructor from your deployed binaries. This might be because of your linker settings - so please check that you have set the linker to link "SDK only". But if that doesn't help then this might be down to some Xamarin optimisation/feature - so you might need to .
As a simple workaround you could try overriding Setup so that you use:
protected override void InitializeViewModelFramework()
{
Mvx.RegisterSingleton<IMvxViewModelLoader>(() => new MvxViewModelLoader>());
}
However, even if this works, then I'd be worried that the linker might be stripping out other symbols in your app - so this might not be enough... you might need to chase this through with Xamarin.
I am using xamarin android 4.10.1 and GooglePlayServices Rev. 12 from xamarin component store. It is mvvmcross application, so I have Core and Android projects. I need push notifications support in my app. So I start with GooglePlayServices component. I write this code:
var gcm = GoogleCloudMessaging.GetInstance(this);
var key = gcm.Register(new[] { "senderId" });
and it doesn't work, I fount that I need to run it on async thread, one solution I found here: http://forums.xamarin.com/discussion/8420/error-calling-googlecloudmessaging-register
ThreadPool.QueueUserWorkItem(o =>
{
var gcm = GoogleCloudMessaging.GetInstance(this);
var key = gcm.Register(new[] { Settings.GmcSenderId });
});
This code works, my service handle registration message, but I need this registration key in my mvvmcross ViewModel. So I start to register with Task approach:
var task = Task.Factory.Startnew(() =>
{
var gcm = GoogleCloudMessaging.GetInstance(this);
return gcm.Register(new[] { Settings.GmcSenderId });
});
var key = task.Result; // wait for result
// key is needed to execute code here
// ViewModel.Key = key;
But every time I receive SERVICE_NOT_AVAILABLE Exception, also I have try to sync with ManualResetEvent object, but still have exceptions.
Maybe some one know solution, how to bring registration Id to ViewModel class from View (activity). Or maybe you have some example with mvvmcross and receiving registration Id in view model...
My code with Task:
public string Register(string senderId)
{
var task = Task.Factory.StartNew(() =>
{
var context = Mvx.Resolve<IMvxAndroidCurrentTopActivity>().Activity;
var gcm = GoogleCloudMessaging.GetInstance(context);
return gcm.Register(senderId);
});
return task.Result; // exception here!
}
Detailed exception:
InnerException {Java.IO.IOException: Exception of type 'Java.IO.IOException' was thrown.
at Android.Runtime.JNIEnv.CallObjectMethod (IntPtr jobject, IntPtr jmethod, Android.Runtime.JValue[] parms) [0x00064] in /Users/builder/data/lanes/monodroid-mlion-monodroid-4.10.1-branch/d23a19bf/source/monodroid/src/Mono.Android/src/Runtime/JNIEnv.g.cs:194
at Android.Gms.Gcm.GoogleCloudMessaging.Register (System.String[] p0) [0x00000] in <filename unknown>:0
at Fiocx.Android.Code.NotificationService+<>c__DisplayClass1.<Register>b__0 () [0x00013] in d:\ASUS\Work\Programming\.NET\Fiocx.CloudApp\mobile_src\Fiocx.Mobile\Fiocx.Android\Code\NotificationService.cs:33
at System.Threading.Tasks.TaskActionInvoker+FuncInvoke`1[System.String].Invoke (System.Threading.Tasks.Task owner, System.Object state, System.Threading.Tasks.Task context) [0x00000] in <filename unknown>:0
at System.Threading.Tasks.Task.InnerInvoke () [0x00000] in <filename unknown>:0
at System.Threading.Tasks.Task.ThreadStart () [0x00000] in <filename unknown>:0
--- End of managed exception stack trace ---
java.io.IOException: SERVICE_NOT_AVAILABLE
at com.google.android.gms.gcm.GoogleCloudMessaging.register(Unknown Source)
at dalvik.system.NativeStart.run(Native Method)
} Java.IO.IOException
Similar problem with a solution: GCM SERVICE_NOT_AVAILABLE on Android 2.2
Btw have you tried using PushSharp?
https://github.com/Redth/PushSharp