我正在尝试制作自定义控件库;我开始创建一个带有简单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文件并做了完全相同的事情然后引用它并且它工作了;但我真正想要做的是创建一个单独的项目来保存我的自定义控件。
任何帮助都将不胜感激。
编辑:如果有人遇到这个问题,我通过强制联系过程找到了解决方案
Infrastructure
public static class Infrastructure
{
public static void init()
{
}
}
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);
}
}
}
答案 0 :(得分:1)
这是一个已知的链接问题,它是在所有引用都在XAML中时引起的。您可以尝试此答案中提供的选项 - https://stackoverflow.com/a/43574309/7292772