Xamarin-在xmlns clr-namespace中找不到类型 [英] Xamarin - Type not found in xmlns clr-namespace

查看:119
本文介绍了Xamarin-在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屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆