【问题标题】:Xaml Parse Exception Button RedererXaml Parse Exception Button Rederer
【发布时间】: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


【解决方案1】:

你试过了吗

xmlns:local="clr-namespace:MyApp"

代替

xmlns:local="clr-namespace:MyApp;assembly=MyApp"

?如果它有效,您可能已经重命名了您的项目或更改了您的命名空间。它已经发生在我身上。检查控件的命名空间并确保它与 XAML 中的相同。

【讨论】:

  • 这对我有用!但是排除装配部分是什么意思?不需要吗?
  • 我想如果您在多个程序集中有相同的命名空间,则需要程序集部分。大多数情况下,情况并非如此,这就是为什么删除它没有效果(或者如果您重命名项目或更改命名空间,则可以解决您的问题)。
  • 但是考虑到这个问题的原因是项目被重命名了,难道不应该有其他方法来解决这个问题吗?喜欢更改某些配置文件中的某些内容?
猜你喜欢
  • 1970-01-01
  • 2012-07-10
  • 1970-01-01
  • 1970-01-01
  • 2017-04-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多