我正在嘗試創建一個按鈕渲染器。我遵循自定義渲染器在此處找到的條目:Xaml解析異常按鈕Rederer
該解決方案使用PLC構建。
我使用錯誤的程序集嗎?
Xamarin.Forms.Xaml.XamlParseException被拋出
類型本地:在錯誤
更多信息則myButton的xmlns中未發現:地方= 「CLR的命名空間:MyApp的;裝配= 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編譯以獲取有關根本原因的更多信息:https://developer.xamarin.com/guides/xamarin-forms/xaml/xamlc/ – Jason
錯誤來自XAML預覽。在模擬器中運行應用程序後,我得不到任何錯誤,並顯示自定義按鈕渲染器。 – MartDavious