Xamarin-在xmlns clr-namespace中找不到类型 [英] Xamarin - Type not found in xmlns clr-namespace
问题描述
我正在制作Xamarin Forms应用程序,解决方案称为RESTTest
,我的共享项目称为RestApp
.
在我的共享项目中,我有一个名为ViewModels
的文件夹,其中包含一个名为MainViewModel.cs
我有一个名为MainPage.xaml
的页面,该页面后面有一个名为MainPage.xaml.cs
的代码.在我的XAML中,我试图包含这样的Viewmodels文件夹:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:RestApp"
x:Class="RestApp.MainPage"
xmlns:ViewModels="clr-namespace:RestApp.ViewModels;assembly=RestApp">
但是当我像这样向页面添加绑定时:
<ContentPage.BindingContext>
<ViewModels:MainViewModel />
</ContentPage.BindingContext>
我遇到了未处理的异常:
Type ViewModels:MainViewModel not found in xmlns clr-namespace:RestApp.ViewModels;assembly=RestApp
我想念什么?
删除命名空间中的; assembly = RestApp",并将链接器行为设置为仅链接SDK组装"对我来说有效,并解决了该问题!/p>
I am making a Xamarin Forms app, the solution is called RESTTest
, my shared project is called RestApp
.
In my shared project I have a folder called ViewModels
, which contains a class called MainViewModel.cs
I have a page called MainPage.xaml
which has a code-behind called MainPage.xaml.cs
. In my XAML I am trying to include my Viewmodels folder like this:
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:RestApp"
x:Class="RestApp.MainPage"
xmlns:ViewModels="clr-namespace:RestApp.ViewModels;assembly=RestApp">
But when I add binding to my page like this:
<ContentPage.BindingContext>
<ViewModels:MainViewModel />
</ContentPage.BindingContext>
I am getting an unhandled exception:
Type ViewModels:MainViewModel not found in xmlns clr-namespace:RestApp.ViewModels;assembly=RestApp
What am I missing?
Removing the ";assembly=RestApp" in the namespace, and setting the linker behaviour to "Link SDK Assemblies Only" worked for me and solved the problem!
这篇关于Xamarin-在xmlns clr-namespace中找不到类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!