简体   繁体   English

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

[英]Xamarin XAML Issue: Inheriting Type not found in xmlns namespace

I want a base class for my Popups to inherit from, that handles callbacks. 我希望我的Popup继承自基类,该基类处理回调。

My approach: Create a class ("CallbackPopup") that inherits from PopupPage ( https://github.com/rotorgames/Rg.Plugins.Popup ) Create XAML+CS files that inherit from CallbackPopup 我的方法:创建一个从PopupPage( https://github.com/rotorgames/Rg.Plugins.Popup )继承的类(“ CallbackPopup”)创建从CallbackPopup继承的XAML + CS文件

CallbackPopup: (My base class for my custom popups) CallbackPopup :(我的自定义弹出窗口的基类)

using Rg.Plugins.Popup.Pages;

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

Inheriting Class - XAML: 继承类-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>

Inheriting Class - CS: 继承类-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();
    }

  //  [...]
}

Error: 错误:

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

I have tested the functionallity of the Popups and it has been successful. 我已经测试了Popups的功能,并且已经成功。 However creating it as a base class and make other popups inherit from it is not working as my error states. 但是,将其创建为基类并让其他弹出窗口继承该类不能作为我的错误状态。 Am I missing something in the XAML declarations, or is inheriting from RG Plugins PopupPage causing the issue? 我是否在XAML声明中缺少某些内容,或者是从RG插件PopupPage继承导致此问题?

http://www.burkharts.net/apps/blog/the-secret-life-of-a-xaml-page/ states: "You cannot derive a Xaml defined Page from another Xaml defined page (unless they only define resources and no content)" May that be the cause of the problem? http://www.burkharts.net/apps/blog/the-secret-life-of-a-xaml-page/指出:“您不能从另一个Xaml定义的页面派生Xaml定义的页面(除非它们仅定义资源和没有内容)“这可能是问题的原因吗? I don't know, if the RG Plugins PopupPages are Xaml defined pages that define more than resources and content. 我不知道RG插件PopupPages是否是Xaml定义的页面,它们定义的不仅仅是资源和内容。

Thanks for your support! 谢谢你的支持!

Well you should put myproject namespace when you initialize CallbackPopup.Content . 好了,当您初始化CallbackPopup.Content时,应该放置myproject命名空间。 That's what error is trying to tell you about :) 这就是试图告诉您的错误:)

Something like this: 像这样:

<myproject:CallbackPopup.Content>
       <!-- [...] -->
</myproject:CallbackPopup.Content>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM