Xamarin XAML问题:在xmlns名称空间中找不到继承类型

时间:2017-09-06 13:27:18

标签: c# xaml inheritance xamarin reference

我希望我的Popups继承基类,处理回调。

我的方法: 创建一个继承自PopupPage(https://github.com/rotorgames/Rg.Plugins.Popup)的类(“CallbackPopup”) 创建从CallbackPopup继承的XAML + CS文件

CallbackPopup:(我的自定义弹出窗口的基类)

using Rg.Plugins.Popup.Pages;

namespace MyProject
{
    public class CallbackPopup : PopupPage
    {
        //[...]
    }
}

继承类 - XAML:

<?xml version="1.0" encoding="utf-8" ?>
<myproject:CallbackPopup xmlns="http://xamarin.com/schemas/2014/forms" <!-- throws the error -->
                                xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
                            xmlns:myproject="clr-namespace:MyProject;assembly=MyProject"
                            x:Class="MyProject.Layout.Popups.InheritingPopup">
    <CallbackPopup.Content>
       <!-- [...] -->
    </CallbackPopup.Content>
</myproject:CallbackPopup>

继承类 - CS:

using Rg.Plugins.Popup.Services;
using System;
using Xamarin.Forms.Xaml;

namespace MyProject.Layout.Popups
{
    [XamlCompilation(XamlCompilationOptions.Compile)]
    public partial class InheritingPopup: CallbackPopup
    {

    public InheritingPopup()
    {
        InitializeComponent();
    }

  //  [...]
}

错误:

Type CallbackPopup not found in xmlns http://xamarin.com/schemas/2014/forms

我测试了Popups的功能,但它已经成功了。 但是,将其创建为基类并使其他弹出窗口继承它并不起作用,因为我的错误状态。 我是否在XAML声明中遗漏了某些内容,或者是从RG插件PopupPage继承而导致此问题?

http://www.burkharts.net/apps/blog/the-secret-life-of-a-xaml-page/州: “你无法从另一个Xaml定义的页面派生Xaml定义的页面(除非它们只定义资源而没有内容)” 可能是问题的原因?我不知道,如果RG插件PopupPages是Xaml定义的页面,它定义的不仅仅是资源和内容。

感谢您的支持!

1 个答案:

答案 0 :(得分:1)

初始化myproject时,您应该放置CallbackPopup.Content命名空间。这就是错误试图告诉你的事情:)

这样的事情:

<myproject:CallbackPopup.Content>
       <!-- [...] -->
</myproject:CallbackPopup.Content>
相关问题