Xamarin Forms.Xaml.XamlParseException
我正在创建一个xamarin行为来验证电子邮件ID,因此我创建了行为文件并尝试将其本地化为XAML文件,但出现以下错误
I am creating a xamarin behaviour to validate an email id, therefore I created the behaviour file and tried to localise it in XAML file but I get the below error
Xamarin.Forms.Xaml.XamlParseException:位置12:10.类型 在xmlns中找不到local:EmailBhvr clr-namespace:Validation.Helpers; assembly = Validation.Helpers
Xamarin.Forms.Xaml.XamlParseException: Position 12:10. Type local:EmailBhvr not found in xmlns clr-namespace:Validation.Helpers;assembly=Validation.Helpers
命名空间:验证
行为代码文件:EmailBhvr
Behaviour Code File: EmailBhvr
这是我的XAML代码:
Here is my XAML code:
<? xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns = "http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:local="clr-namespace:Validation;assembly=Validation"
x:Class="Validation.WelcomePage">
<StackLayout>
<Label Text = "Hello Xamarin" />
< Entry Placeholder="Enter your full name" x:Name="myName">
<Entry.Behaviors>
<local:EmailBhvr />
</Entry.Behaviors>
</Entry>
<Entry Placeholder = "Enter your email" x:Name="myEmail" />
<Entry Placeholder = "Enter password" x:Name="myPassword" IsPassword="True" />
<Entry Placeholder = "Confirm password" x:Name="myConfirmPassword" IsPassword="True" />
<Button Text = "Save" x:Name="SaveRegistration"/>
</StackLayout>
</ContentPage>
这可能与一个已知的链接问题有关-Xamarin编译器最终链接了仅在XAML中具有引用的类(从外部程序集).
This could be related to a known linking issue - where Xamarin compiler ends up linking out classes (from external assemblies) that have references only in XAML.
看起来像EmailBhvr
可能已被编译器链接出去.有几个有关此的链接:
Looks like EmailBhvr
might be getting linked out by the compiler. There are couple of links that talk about this:
- Extending Control plugins > Getting Started
- Force assembly linking
有很多选项可以解决此问题:
There are a lot of options to resolve this:
-
或者,使用 Android 上的保存属性来保存代码和 iOS
-
Or, preserve code using preserve attributes on Android, and iOS
public class Example { [Android.Runtime.Preserve] public Example () { } }
-
或者使用自定义链接.
或者,将项目配置更新为不链接. Android 和
Or, update project configuration to not link. Android, and iOS. Not a recommended option though.