У меня есть этот код XAML:
<?xml version="1.0" encoding="UTF-8"?>
<StackLayout
xmlns ="http://xamarin.com/schemas/2014/forms"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:t="clr-namespace:Templates"
x:Class="Japanese..EntryGrid"
x:Name="this" >
<t:HeaderTemplate Text="ABC" />
<Entry HorizontalOptions="FillAndExpand"
VerticalTextAlignment="{Binding EntryTextAlignment, Converter={StaticResource stringToTextAligmentConverter}, Source={x:Reference this}}"
VerticalOptions="FillAndExpand"
Text="{Binding EntryText, Source={x:Reference this}}" />
</StackLayout>
и этот код C#:
public partial class EntryGrid : StackLayout
{
public EntryGrid()
{
InitializeComponent();
}
public static readonly BindableProperty
EntryTextAlignmentProperty =
BindableProperty.Create(nameof(EntryText),
typeof(TextAlignment),
typeof(EntryGrid),
TextAlignment.Center,
BindingMode.TwoWay);
public string EntryTextAlignment {
get => (string)GetValue(EntryTextAlignmentProperty);
set => SetValue(EntryTextAlignmentProperty, value); }
}
В шаблоне есть больше кода, но я только что включил то, что использовалось для этот вопрос.
То, что я пытаюсь сделать, это установить значение EntryTextAlignment в значение «Center» следующим образом:
<t:EntryGrid EntryTextAlignment="Start"
HeightRequest="150" />
Но он не принимает мой запрос, и текст выравнивается по вертикали в Центр.
Кто-нибудь знает, что я могу делать не так?