baseflow / mvxforms Goto Github PK
View Code? Open in Web Editor NEWSample App with Xamarin.Forms and MvvmCross
Home Page: https://baseflow.com
License: MIT License
Sample App with Xamarin.Forms and MvvmCross
Home Page: https://baseflow.com
License: MIT License
Can you add examples of Mvx::bi.nd
inside this sample as it doesn't seem to be too obvious. I get crashes of the previewer mostly when I attempt it. The example from the medium post wasn't demonstrable.
I encountered a strange issue, hopefully you know how to counter this:
Instead of closing the app, a new (previous?) instance of the app pops up.
I have the same issue in my Forms app once I migrated to MvvmCross.Forms, but I don't see the same behaviour in the Playgrounds sample in the MvvmCross repo.
Hi,
I've just cloned this repo and built and run locally on both android simulator and a google pixel. In both cases the app starts and shows the splash screen then after a short delay crashes. I have not modified the code.
This is my first attempt to use Mvvmcross and Xamarin forms. All I get from the debugger is the following rather unhelpful exception.
Unhandled Exception:
System.ArgumentNullException: Value cannot be null.
Parameter name: source occurred
Can you advise how I might progress to a working solution?
First of all, thanks for example.
But I have a problem integrating your example with other packages that require initialization on each platform (in this case Android). For example, I installed the Acr.UserDialogs package version 6.4.1.
The only thing I modify is the main activity after calling based on the super class I initialize the plugin.
namespace MvxForms.Droid
{
[Activity(Label = "MvxForms.Droid", Icon = "@drawable/icon", Theme = "@style/MyTheme", ConfigurationChanges = ConfigChanges.ScreenSize | ConfigChanges.Orientation)]
public class MainActivity : MvxFormsAppCompatActivity
{
protected override void OnCreate(Bundle bundle)
{
base.OnCreate(bundle);
TabLayoutResource = Resource.Layout.Tabbar;
ToolbarResource = Resource.Layout.Toolbar;
UserDialogs.Init(this);
PullToRefreshLayoutRenderer.Init();
XFGloss.Droid.Library.Init(this, bundle);
//Initializing FFImageLoading
CachedImageRenderer.Init();
}
}
}
Then in the PCL register the instance as a singleton in the IOC container:
namespace MvxForms.Core
{
public class CoreApp : MvvmCross.Core.ViewModels.MvxApplication
{
public override void Initialize()
{
CreatableTypes()
.EndingWith("Service")
.AsInterfaces()
.RegisterAsLazySingleton();
Mvx.RegisterSingleton<IUserDialogs>(() => UserDialogs.Instance);
RegisterAppStart<ViewModels.MvxFormsViewModel>();
}
}
}
Modify your example ViewModel to request the injection of the service.
namespace MvxForms.Core.ViewModels
{
public class MvxFormsViewModel : MvxViewModel
{
protected readonly IUserDialogs _userDialogs;
public MvxFormsViewModel(IUserDialogs userDialogs)
{
_userDialogs = userDialogs;
}
public override Task Initialize()
{
//TODO: Add starting logic here
return base.Initialize();
}
public IMvxCommand ResetTextCommand => new MvxCommand(ResetText);
private void ResetText()
{
Text = "Hello MvvmCross";
}
private string _text = "Hello MvvmCross";
public string Text
{
get { return _text; }
set { SetProperty(ref _text, value); }
}
}
}
When launching the application, get the following error:
This is the trace of the error that I see by console:
mvx:Warning: 1.39 Exception masked MvxException: Failed to construct and initialize ViewModel for type MvxForms.Core.ViewModels.MvxFormsViewModel from locator MvxDefaultViewModelLocator - check InnerException for more information
at MvvmCross.Core.ViewModels.MvxViewModelLoader.LoadViewModel (MvvmCross.Core.ViewModels.MvxViewModelRequest request, MvvmCross.Core.ViewModels.IMvxBundle savedState, MvvmCross.Core.ViewModels.IMvxViewModelLocator viewModelLocator) [0x00020] in D:\git\MvvmCross\MvvmCross\Core\Core\ViewModels\MvxViewModelLoader.cs:73
at MvvmCross.Core.ViewModels.MvxViewModelLoader.LoadViewModel (MvvmCross.Core.ViewModels.MvxViewModelRequest request, MvvmCross.Core.ViewModels.IMvxBundle savedState) [0x00020] in D:\git\MvvmCross\MvvmCross\Core\Core\ViewModels\MvxViewModelLoader.cs:59
at MvvmCross.Forms.Presenters.MvxPresenterHelpers.LoadViewModel (MvvmCross.Core.ViewModels.MvxViewModelRequest request) [0x00017] in D:\git\MvvmCross\MvvmCross-Forms\MvvmCross.Forms\Presenters\MvxPresenterHelpers.cs:25
at MvvmCross.Forms.Presenters.MvxFormsPagePresenter.TryShowPage (MvvmCross.Core.ViewModels.MvxViewModelRequest request) [0x0000c] in D:\git\MvvmCross\MvvmCross-Forms\MvvmCross.Forms\Presenters\MvxFormsPagePresenter.cs:88
at MvvmCross.Forms.Presenters.MvxFormsPagePresenter.Show (MvvmCross.Core.ViewModels.MvxViewModelRequest request) [0x00000] in D:\git\MvvmCross\MvvmCross-Forms\MvvmCross.Forms\Presenters\MvxFormsPagePresenter.cs:60
at MvvmCross.Droid.Views.MvxAndroidViewDispatcher+<>c__DisplayClass2_0.<ShowViewModel>b__0 () [0x00000] in D:\git\MvvmCross\MvvmCross\Droid\Droid\Views\MvxAndroidViewDispatcher.cs:26
at MvvmCross.Droid.Views.MvxAndroidMainThreadDispatcher.RequestMainThreadAction (System.Action action, System.Boolean maskExceptions) [0x00020] in D:\git\MvvmCross\MvvmCross\Droid\Droid\Views\MvxAndroidMainThreadDispatcher.cs:20
at MvvmCross.Droid.Views.MvxAndroidViewDispatcher.ShowViewModel (MvvmCross.Core.ViewModels.MvxViewModelRequest request) [0x00014] in D:\git\MvvmCross\MvvmCross\Droid\Droid\Views\MvxAndroidViewDispatcher.cs:26
at MvvmCross.Core.ViewModels.MvxNavigatingObject.ShowViewModelImpl (System.Type viewModelType, MvvmCross.Core.ViewModels.IMvxBundle parameterBundle, MvvmCross.Core.ViewModels.IMvxBundle presentationBundle) [0x00023] in D:\git\MvvmCross\MvvmCross\Core\Core\ViewModels\MvxNavigatingObject.cs:117
at MvvmCross.Core.ViewModels.MvxNavigatingObject.ShowViewModel (System.Type viewModelType, MvvmCross.Core.ViewModels.IMvxBundle parameterBundle, MvvmCross.Core.ViewModels.IMvxBundle presentationBundle) [0x00000] in D:\git\MvvmCross\MvvmCross\Core\Core\ViewModels\MvxNavigatingObject.cs:109
at MvvmCross.Core.ViewModels.MvxNavigatingObject.ShowViewModel[TViewModel] (MvvmCross.Core.ViewModels.IMvxBundle parameterBundle, MvvmCross.Core.ViewModels.IMvxBundle presentationBundle) [0x00000] in D:\git\MvvmCross\MvvmCross\Core\Core\ViewModels\MvxNavigatingObject.cs:81
at MvvmCross.Core.ViewModels.MvxAppStart`1[TViewModel].Start (System.Object hint) [0x00013] in D:\git\MvvmCross\MvvmCross\Core\Core\ViewModels\MvxAppStart.cs:22
at MvvmCross.Droid.Views.MvxSplashScreenActivity.TriggerFirstNavigate () [0x00006] in D:\git\MvvmCross\MvvmCross\Droid\Droid\Views\MvxSplashScreenActivity.cs:88
at MvxForms.Droid.SplashScreen.TriggerFirstNavigate () [0x00012] in /Users/BISITE/Projects/MvxForms-master/MvxForms.Droid/SplashScreen.cs:24
at MvvmCross.Droid.Views.MvxSplashScreenActivity.InitializationComplete () [0x00009] in D:\git\MvvmCross\MvvmCross\Droid\Droid\Views\MvxSplashScreenActivity.cs:82
at MvvmCross.Droid.Platform.MvxAndroidSetupSingleton.<InitializeFromSplashScreen>b__7_1 () [0x00000] in D:\git\MvvmCross\MvvmCross\Droid\Droid\Platform\MvxAndroidSetupSingleton.cs:100
at MvvmCross.Platform.Core.MvxMainThreadDispatcher.ExceptionMaskedAction (System.Action action) [0x00000] in D:\git\MvvmCross\MvvmCross\Platform\Platform\Core\MvxMainThreadDispatcher.cs:21
InnerException was MvxException: Problem creating viewModel of type MvxFormsViewModel
at MvvmCross.Core.ViewModels.MvxDefaultViewModelLocator.Load (System.Type viewModelType, MvvmCross.Core.ViewModels.IMvxBundle parameterValues, MvvmCross.Core.ViewModels.IMvxBundle savedState) [0x0000f] in D:\git\MvvmCross\MvvmCross\Core\Core\ViewModels\MvxDefaultViewModelLocator.cs:37
at MvvmCross.Core.ViewModels.MvxViewModelLoader.LoadViewModel (MvvmCross.Core.ViewModels.MvxViewModelRequest request, MvvmCross.Core.ViewModels.IMvxBundle savedState, MvvmCross.Core.ViewModels.IMvxViewModelLocator viewModelLocator) [0x0000e] in D:\git\MvvmCross\MvvmCross\Core\Core\ViewModels\MvxViewModelLoader.cs:69
InnerException was ArgumentException: In android, you must call UserDialogs.Init(Activity) from your first activity OR UserDialogs.Init(App) from your custom application OR provide a factory function to get the current top activity via UserDialogs.Init(() => supply top activity)
at Acr.UserDialogs.UserDialogs+<>c.<.cctor>b__8_0 () [0x00000] in C:\dev\acr\userdialogs\src\Acr.UserDialogs.Shared\UserDialogs.cs:19
at System.Lazy`1[T].CreateValue () [0x00081] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Lazy`1[T].LazyInitValue () [0x00080] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at System.Lazy`1[T].get_Value () [0x0003a] in <896ad1d315ca4ba7b117efb8dacaedcf>:0
at Acr.UserDialogs.UserDialogs.get_Instance () [0x00000] in C:\dev\acr\userdialogs\src\Acr.UserDialogs.Shared\UserDialogs.cs:69
at MvxForms.Core.CoreApp+<>c.<Initialize>b__0_0 () [0x00000] in /Users/BISITE/Projects/MvxForms-master/MvxForms.Core/CoreApp.cs:16
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer+<>c__DisplayClass33_0`1[TInterface].<RegisterSingleton>b__0 () [0x00000] in D:\git\MvvmCross\MvvmCross\Platform\Platform\IoC\MvxSimpleIoCContainer.cs:290
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer+ConstructingSingletonResolver.Resolve () [0x00028] in D:\git\MvvmCross\MvvmCross\Platform\Platform\IoC\MvxSimpleIoCContainer.cs:136
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.InternalTryResolve (System.Type type, MvvmCross.Platform.IoC.MvxSimpleIoCContainer+IResolver resolver, System.Object& resolved) [0x00041] in D:\git\MvvmCross\MvvmCross\Platform\Platform\IoC\MvxSimpleIoCContainer.cs:445
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.InternalTryResolve (System.Type type, System.Nullable`1[T] requiredResolverType, System.Object& resolved) [0x0002e] in D:\git\MvvmCross\MvvmCross\Platform\Platform\IoC\MvxSimpleIoCContainer.cs:403
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.InternalTryResolve (System.Type type, System.Object& resolved) [0x00000] in D:\git\MvvmCross\MvvmCross\Platform\Platform\IoC\MvxSimpleIoCContainer.cs:385
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.TryResolve (System.Type type, System.Object& resolved) [0x00011] in D:\git\MvvmCross\MvvmCross\Platform\Platform\IoC\MvxSimpleIoCContainer.cs:180
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.GetIoCParameterValues (System.Type type, System.Reflection.ConstructorInfo firstConstructor) [0x00015] in D:\git\MvvmCross\MvvmCross\Platform\Platform\IoC\MvxSimpleIoCContainer.cs:494
at MvvmCross.Platform.IoC.MvxSimpleIoCContainer.IoCConstruct (System.Type type) [0x0002c] in D:\git\MvvmCross\MvvmCross\Platform\Platform\IoC\MvxSimpleIoCContainer.cs:312
at MvvmCross.Platform.Mvx.IocConstruct (System.Type t) [0x00006] in D:\git\MvvmCross\MvvmCross\Platform\Platform\Mvx.cs:169
at MvvmCross.Core.ViewModels.MvxDefaultViewModelLocator.Load (System.Type viewModelType, MvvmCross.Core.ViewModels.IMvxBundle parameterValues, MvvmCross.Core.ViewModels.IMvxBundle savedState) [0x00000] in D:\git\MvvmCross\MvvmCross\Core\Core\ViewModels\MvxDefaultViewModelLocator.cs:33
Could you give me some tips on how I can solve this problem? Thank you very much in advance.
As discovered in #8, the Setup and SplashScreen are not correct.
Should be:
public class Setup : MvxFormsAndroidSetup<CoreApp, App>
And the line:
Should be:
public class SplashScreen : MvxFormsSplashScreenActivity<Setup, CoreApp, App>
MvvmCross is now up to 5.3.1, which introduced a number of namespace changes.
As such, this project is no longer an up to date guide how to set up MvvmCross for Forms as someone doing so will naturally be binding to the latest.
If you would like to open up to pull requests, I have a branch of this project that updates to 5.3.1 and fixes a number of small issues that come out of this.
On a separate note, the content at https://www.mvvmcross.com/documentation/platform/forms/xamarin-forms?scroll=435/ (https://github.com/MvvmCross/MvvmCross/blob/master/docs/_documentation/platform/forms/xamarin-forms.md) is unfortunately also out of date (even compare to the master version of this project). I could possibly have a go at patching this up.
Expected behaviour.
Application should run properly.
Actual behaviour.
Application throws an exception says that, SetFlags must be called before Init.
A sample xamarin forms project works properly with the FastRenderer features (Not contain MvvmCross). But if applying the same in Xamarin forms with MvvmCross app fails.
Could you please help me on this?
Expected behaviour.
Application should run properly.
Actual behaviour.
Application throws an exception says that, SetFlags must be called before Init.
A sample xamarin forms project works properly with the FastRenderer features (Not contain MvvmCross). But if applying the same in Xamarin forms with MvvmCross app fails.
Could you please help me on this?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.