最終的にローカリゼーションを実装するために、Xamarin フォームでカスタム マークアップ拡張機能を使用しようとしています。Xamarin フォームの例の行を長くしようとしています。
拡張機能を使用する 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:CRI.MAP.Mobile.Views;assembly=CRI.MAP.Mobile"
x:Class="CRI.MAP.Mobile.Views.CustomerSearchPage">
<StackLayout>
<Button
Text="{local:Translate Clear}"
Command="{Binding ClearCommand}" />
</StackLayout>
Translation Extension Markup のコードは次のとおりです。
using System;
using Xamarin.Forms.Xaml;
using Xamarin.Forms;
using System.Diagnostics;
namespace CRI.MAP.Mobile.Views
{
// You exclude the 'Extension' suffix when using in Xaml markup
[ContentProperty ("Text")]
public class TranslateExtension : IMarkupExtension
{
public string Text { get; set; }
public object ProvideValue (IServiceProvider serviceProvider)
{
//if (Text == null)
// return null;
//Debug.WriteLine ("Provide: " + Text);
// Do your translation lookup here, using whatever method you require
//var translated = L10n.Localize (Text);
//return translated;
return "hello";
}
}
}
それが問題の原因である場合に備えて、コードの一部をコメントアウトしました。
これを実行しようとするたびに、次のエラーが表示されます: Xamarin.Forms.Xaml.XamlParseException: MarkupExtension not found for local:Translate. 私が見ているすべての例は同じように行われているように見えるので、なぜマークアップ拡張機能が見つからないのか、私は非常に混乱しています。これがなぜなのか誰か知っていますか?一般的に、Xamarin フォームの良い例を見つけるのに多くの問題があります。