【发布时间】:2017-07-26 19:45:33
【问题描述】:
我正在尝试创建一个按钮渲染器。我按照自定义渲染器找到了此处的条目:
解决方案是使用 PLC 构建的。
我是否使用了错误的程序集?
有关错误的更多信息:
Xamarin.Forms.Xaml.XamlParseException 被抛出
类型 local:MyButton not found in xmlns:local="clr-namespace:MyApp;assembly=MyApp"
https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/custom-renderer/entry/
我得到一个 xaml 解析异常错误。
<?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:MyApp;assembly=MyApp"
x:Class="MyApp.LoginPage"
BackgroundColor="White">
<StackLayout>
<local:MyButton
Text="Login"
TextColor="Blue"
BackgroundColor="Transparent"
HorizontalOptions="CenterAndExpand" />
</StackLayout>
</ContentPage>
Android 渲染器:
using Xamarin.Forms.Platform.Android;
using Xamarin.Forms;
using DeliveryTracker;
using DeliveryTracker.Droid;
[assembly: ExportRenderer(typeof(MyButton), typeof(MyButtonRenderer))]
namespace MyApp.Droid
{
class MyButtonRenderer : ButtonRenderer
{
protected override void OnDraw(Android.Graphics.Canvas canvas)
{
base.OnDraw(canvas);
}
}
}
在表格中:
using System;
using Xamarin.Forms;
namespace MyApp
{
public class MyButton : Button
{
public MyButton()
{
}
}
}
【问题讨论】:
-
你没有告诉我们你看到了什么错误。 “Xaml 解析异常”并没有给我们足够的信息。错误信息是什么?它是否指定了 XAML 中的特定位置?
-
启用 XAML 编译以获取有关根本原因的更多信息:developer.xamarin.com/guides/xamarin-forms/xaml/xamlc
-
错误来自 XAML 预览。在模拟器中运行应用程序后,我没有收到任何错误,它显示了自定义按钮渲染器。
-
@MartDavious 提交错误:bugzilla.xamarin.com
-
尝试删除命名空间声明中的
";assembly=MyApp"部分,因此只需删除xmlns:local="clr-namespace:MyApp"。您是否通过任何更改重命名了您的项目或命名空间或其他内容?确保 XAML 中的命名空间与声明控件的位置相同。
标签: c# xamarin xamarin.ios xamarin.android xamarin.forms