卡特尔 Xamarin.Forms
Catel with Xamarin.Forms
无法让Xamarin.Forms和Catel一起工作
我看到了这个 sample 但它似乎已经过时了。
当我通过 NuGet 下载 Catel 时,我遇到了不同版本的不同问题:
v5.1:
编译时异常:
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:
运行时异常(创建时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.*
使用ViewModelBase
:
创建应用程序对象时出现运行时异常:
System.TypeLoadException:无法使用令牌解析类型 01000097(来自 typeref,class/assembly System.Reflection.BindingFlags,Catel.Core,版本=4.5.4.0,文化=中性,PublicKeyToken=null)
我的实现 IViewModel
:
好的,MainPage 加载、绑定有效,Constructor 通过参数获得正确的服务,但是,例如,当我调用“_uiVisualizerService.Show(subPageViewModel);”时从命令中,它抛出 'InvalidCastException'。异常前 Catel 日志中的最后一行:Injecting properties into type 'SubPage' after construction
。但是 SubPage 和 SubPageViewModel 绝对是空的。
详情:
---> System.InvalidCastException: Specified cast is not valid.
at Catel.Services.UIVisualizerService+<ShowAsync>d__9.MoveNext () [0x00096]
in C:\CI_WS\Ws969\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\Ws969\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\Ws969\Source\Catel\src\Catel.MVVM\Catel.MVVM.Xamarin.Forms\Services\UIVisualizerService.cs:151 <---
我是做什么的:
将 android
项目中的默认 Catel.MVVM.dll
引用从 MonoAndroid
更改为 portable-net45+wp8+win8+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10+UAP10
。如果不这样做,编译将失败。
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、64 倍。
Xamarin.Forms: 2.3.4.267
非常感谢任何帮助。
团队正在努力改进对 Xamarin.Forms 的支持。目前没有例子。预计在接下来的几个月内最终确定对 Xamarin.Forms 的 v5 支持。
无法让Xamarin.Forms和Catel一起工作
我看到了这个 sample 但它似乎已经过时了。
当我通过 NuGet 下载 Catel 时,我遇到了不同版本的不同问题:
v5.1:
编译时异常:
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:
运行时异常(创建时
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.*
使用
ViewModelBase
:创建应用程序对象时出现运行时异常: System.TypeLoadException:无法使用令牌解析类型 01000097(来自 typeref,class/assembly System.Reflection.BindingFlags,Catel.Core,版本=4.5.4.0,文化=中性,PublicKeyToken=null)
我的实现
IViewModel
:好的,MainPage 加载、绑定有效,Constructor 通过参数获得正确的服务,但是,例如,当我调用“_uiVisualizerService.Show(subPageViewModel);”时从命令中,它抛出 'InvalidCastException'。异常前 Catel 日志中的最后一行:
Injecting properties into type 'SubPage' after construction
。但是 SubPage 和 SubPageViewModel 绝对是空的。详情:
---> System.InvalidCastException: Specified cast is not valid. at Catel.Services.UIVisualizerService+<ShowAsync>d__9.MoveNext () [0x00096] in C:\CI_WS\Ws969\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\Ws969\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\Ws969\Source\Catel\src\Catel.MVVM\Catel.MVVM.Xamarin.Forms\Services\UIVisualizerService.cs:151 <---
我是做什么的:
将
android
项目中的默认Catel.MVVM.dll
引用从MonoAndroid
更改为portable-net45+wp8+win8+wpa81+MonoAndroid10+MonoTouch10+Xamarin.iOS10+UAP10
。如果不这样做,编译将失败。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、64 倍。 Xamarin.Forms: 2.3.4.267
非常感谢任何帮助。
团队正在努力改进对 Xamarin.Forms 的支持。目前没有例子。预计在接下来的几个月内最终确定对 Xamarin.Forms 的 v5 支持。