2

I can't get Xamarin.Forms and Catel work together.

I saw this sample but it seems it's out of date.

When I download Catel via NuGet, i get different issues for different versions:

  • v5.1:

    Compile-time exception:

    Exception while loading assemblies: System.IO.FileNotFoundException: Could not load assembly 'Obsolete, Version=4.2.4.0, Culture=neutral, PublicKeyToken=1ca091877d12ca03'. Perhaps it doesn't exist in the Mono for Android profile?

  • v5.0:

    Runtime exception (when creating new App();):

    Could not load signature of Catel.MVVM.IViewModelFactory:CreateViewModel due to: Could not resolve type with token 01000061 (from typeref, class/assembly System.ComponentModel.IDataErrorInfo, Catel.Core, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null) assembly:Catel.Core, Version=5.0.0.0, Culture=neutral, PublicKeyToken=null type:System.ComponentModel.IDataErrorInfo member:<none>

  • v4.5.*

    • Using ViewModelBase:

      Runtime exception when creating Application object: System.TypeLoadException: Could not resolve type with token 01000097 (from typeref, class/assembly System.Reflection.BindingFlags, Catel.Core, Version=4.5.4.0, Culture=neutral, PublicKeyToken=null)

    • My implementation of IViewModel:

      Ok, MainPage loading, binding works, Constructor gets right services via parameters, but, for example, when I call '_uiVisualizerService.Show( subPageViewModel );' from command, it throws 'InvalidCastException'. Last line in Catel log before exception: Injecting properties into type 'SubPage' after construction. But SubPage and SubPageViewModel are absolutely empty.

      Details:

      ---> System.InvalidCastException: Specified cast is not valid. at Catel.Services.UIVisualizerService+<ShowAsync>d__9.MoveNext () [0x00096] in C:\CI_WS\Ws\97969\Source\Catel\src\Catel.MVVM\Catel.MVVM.Xamarin.Forms\Services\UIVisualizerService.cs:151 at System.Threading.Tasks.Task.ThrowIfExceptional (System.Boolean includeTaskCanceledExceptions) [0x00011] in <183b200ee49746d48fc781625979428e>:0 at System.Threading.Tasks.Task'1[TResult].GetResultCore (System.Boolean waitCompletionNotification) [0x0002b] in <183b200ee49746d48fc781625979428e>:0 at System.Threading.Tasks.Task'1[TResult].get_Result () [0x0000f] in <183b200ee49746d48fc781625979428e>:0 at Catel.Services.UIVisualizerService.Show (Catel.MVVM.IViewModel viewModel, System.EventHandler``1[TEventArgs] completedProc) [0x00000] in C:\CI_WS\Ws\97969\Source\Catel\src\Catel.MVVM\Catel.MVVM.Xamarin.Forms\Services\UIVisualizerService.cs:125 at XamarinFormsCatel.ViewModels.MainPageViewModel.OnGo () [0x00015] in C:\!Work\Test\XamarinFormsCatel\XamarinFormsCatel\XamarinFormsCatel\XamarinFormsCatel\ViewModels\MainPageViewModel.cs:34 at Xamarin.Forms.Command+<>c__DisplayClass3_0.<.ctor>b__0 (System.Object o) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Command.cs:73 at Xamarin.Forms.Command.Execute (System.Object parameter) [0x00000] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Command.cs:107 at Xamarin.Forms.Button.Xamarin.Forms.IButtonController.SendClicked () [0x0000a] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Core\Button.cs:121 at Xamarin.Forms.Platform.Android.AppCompat.ButtonRenderer+ButtonClickListener.OnClick (Android.Views.View v) [0x0000b] in C:\BuildAgent3\work\ca3766cfc22354a1\Xamarin.Forms.Platform.Android\AppCompat\ButtonRenderer.cs:298 at Android.Views.View+IOnClickListenerInvoker.n_OnClick_Landroid_view_View_ (System.IntPtr jnienv, System.IntPtr native__this, System.IntPtr native_v) [0x0000f] in <71828dd8fb5f4508815e23d6996c45c2>:0 at (wrapper dynamic-method) System.Object:4c9f6786-8ab0-4bd8-bdb1-4cc7a3d7ddc7 (intptr,intptr,intptr) -> (Inner Exception #0) System.InvalidCastException: Specified cast is not valid. at Catel.Services.UIVisualizerService+<ShowAsync>d__9.MoveNext () [0x00096] in C:\CI_WS\Ws\97969\Source\Catel\src\Catel.MVVM\Catel.MVVM.Xamarin.Forms\Services\UIVisualizerService.cs:151 <---

What i do:

  • Change defalt Catel.MVVM.dll reference in android project from MonoAndroid to portable-net45+wp8+win8+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10+UAP10. if this is not done, compilation will fail.

  • MainPage.xaml

    <catel:ContentPage ... xmlns:catel="clr-namespace:Catel.Windows.Controls;assembly=Catel.MVVM">

  • MainPageViewModel.cs

    public class MainPageViewModel : ViewModelBase { }

  • App.cs

    public class App : Catel.Xamarin.Forms.Application<Views.MainPage> { }

  • MainActivity.cs (Android)

    public class MainActivity : Xamarin.Forms.Platform.Android.FormsAppCompatActivity
    {
        protected override void OnCreate( Bundle bundle )
        {
            TabLayoutResource = Resource.Layout.Tabbar;
            ToolbarResource = Resource.Layout.Toolbar;
    
            base.OnCreate( bundle );
    
            Xamarin.Forms.Forms.Init( this, bundle );
    
            var app = new App();
            LoadApplication( app );
        }
    }
    

Windows 7, 64x. Xamarin.Forms: 2.3.4.267

Any help very appreciated.

Billal Begueradj
  • 20,717
  • 43
  • 112
  • 130
Sam Sch
  • 642
  • 7
  • 15

1 Answers1

-1

The team is working on improved support for Xamarin.Forms. At the moment there are no examples. The expectation is to finalize v5 support for Xamarin.Forms on this over the next few months.

Geert van Horrik
  • 5,689
  • 1
  • 18
  • 32