代码之家  ›  专栏  ›  技术社区  ›  Muhand Jumah

Xamarin。形式。Xaml。XamlParseException:位置51:26

  •  0
  • Muhand Jumah  · 技术社区  · 7 年前

    我正在尝试制作一个自定义控件库;我首先创建了一个带有简单ContentView控件的项目;然后我构建它并将其导入到我的第二个项目中,然后像这样在我的XAML中引用它 xmlns:CustomControls="clr-namespace:MXControls.Other;assembly=MXControls"

    我用这行代码调用我的控件:

    <CustomControls:Checkbox/>

    但不幸的是,我得到了这个错误。 Xamarin.Forms.Xaml.XamlParseException: Position 51:26. Type CustomControls:Checkbox not found in xmlns clr-namespace:MXControls.Other;assembly=MXControls

    我仔细检查了程序集名称和命名空间,它们完全正确。

    我做了进一步的调查,并将其复制到我的主要项目中;所以在我的同一个项目中,我创建了一个。XAML文件,并做了完全相同的事情,然后引用,它的工作;但我真正想做的是创建一个单独的项目,它将保存我的自定义控件。

    编辑:如果有人遇到这个问题,我可以通过强制链接过程来解决

    1. 在我的库项目中,我添加了一个新的静态类并将其命名为 Infrastructure
    2. 我添加了一个不做任何事情的静态方法 public static class Infrastructure { public static void init() { } }
    3. 我去了我的项目,该项目将导入库,在我的IOS项目下,我去了 AppDelegate.cs Infrastructure.Init(); FinishedLaunching 方法,显然您必须使用正确的命名空间 e.g. using MXControls;

    ios项目的完整代码

        using System;
        using System.Collections.Generic;
        using System.Linq;
    
        using Foundation;
        using UIKit;
        using MXControls3;
        namespace LeagueStalker.iOS
        {
        // The UIApplicationDelegate for the application. This class is responsible for launching the 
        // User Interface of the application, as well as listening (and optionally responding) to 
        // application events from iOS.
        [Register("AppDelegate")]
        public partial class AppDelegate : global::Xamarin.Forms.Platform.iOS.FormsApplicationDelegate
        {
            //
            // This method is invoked when the application has loaded and is ready to run. In this 
            // method you should instantiate the window, load the UI into it and then make the window
            // visible.
            //
            // You have 17 seconds to return from this method, or iOS will terminate your application.
            //
            public override bool FinishedLaunching(UIApplication app, NSDictionary options)
            {
                global::Xamarin.Forms.Forms.Init ();
    
                Infrastructure.Init();
    
    
                LoadApplication (new LeagueStalker.App ());
                UIApplication.SharedApplication.SetStatusBarStyle(UIStatusBarStyle.LightContent, false);
    
                return base.FinishedLaunching (app, options);
    
            }
        }
      }
    
    1 回复  |  直到 7 年前
        1
  •  1
  •   Sharada    7 年前

    这是一个已知的链接问题,当所有引用都在XAML中时会导致该问题。您可以尝试此答案中的可用选项- https://stackoverflow.com/a/43574309/7292772