【问题标题】:The Type "name" was not found - Xamarin找不到类型“名称” - Xamarin
【发布时间】:2018-08-29 09:21:00
【问题描述】:

我正在尝试使用 Xamarin 表单实现 TabbedPage。和TabbedPage and Content pages are not showing很像

但是我有一个关于如何从 MainPage.xam 中包含其他 xaml 文件的快速问题:

这是我的代码: 主页:

<TabbedPage xmlns="http://xamarin.com/schemas/2014/forms"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:local="clr-namespace:Assignment"
        x:Class="Assignment.MainPage">
<TabbedPage.Children>

    <local:Alarm /> "The type 'local:Alarm' was not found. Verify that you are not missing..."

</TabbedPage.Children>

上述错误是唯一的构建错误。

Alarm.xaml:

<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms"
         xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
         x:Class="Assignment.Droid.Resources.layout.Alarm">
<ContentPage.Content>
    <StackLayout>
        <Label Text="Welcome to Xamarin.Forms!"
            VerticalOptions="CenterAndExpand" 
            HorizontalOptions="CenterAndExpand" />
    </StackLayout>
</ContentPage.Content>
</ContentPage>

这是我的项目结构:

在另一个链接上,我看到他将他的 xaml 文件放在布局文件夹中。

这是正确的设置吗?我想我错过了一些简单的事情。

【问题讨论】:

  • 只需将Alarm.xaml 移动到Assignment 下的共享代码。将其从 Android 资源中取出
  • 喜欢这个?同样的错误ibb.co/iZxwsp
  • 即使使用x:Class="Assignment" 也会出错?

标签: visual-studio xaml xamarin.forms


【解决方案1】:

正如 Greggz 所说:将其移至您的共享项目。

然后您将不得不更改命名空间,因为这才是真正重要的。在 .NET 领域,习惯上您的命名空间等于文件系统上的路径。

在你 Alarm.xaml 中,将这一行:x:Class="Assignment.Droid.Resources.layout.Alarm" 更改为 x:Class="Assignment.Alarm"

然后进入您的代码隐藏文件,Alarm.xaml.cs 文件并在那里更改命名空间。所以把namespace Assignment.Droid.Resources.layout改成namespace Assignment

由于 XAML 和代码隐藏是作为部分类实现的,因此需要同步。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2018-06-01
    • 2017-10-09
    • 1970-01-01
    • 2017-11-26
    • 2014-07-23
    • 2019-01-17
    • 1970-01-01
    相关资源
    最近更新 更多