0
我想显示文本在中心对齐。问题是,一旦我更新文本,它就会被切断。 如果我使用“Fill”作为HorizontalOptions,文本不会被截断,但文本不在中心。Xamarin.Forms中更新后编辑器中的中心文本
实施例是基于在表格编辑器样品:
public class EditorPageCode : ContentPage
{
Editor styledEditor = new Editor();
Editor centerText = new Editor();
Editor customEditor = new Editor();
public EditorPageCode()
{
var layout = new StackLayout { Padding = new Thickness(5, 10) };
this.Title = "Editor Demo - Code";
layout.Children.Add(new Label { Text = "This page demonstrates the Editor View. The Editor is used for collecting text that is expected to take more than one line." });
styledEditor = new Editor
{
Text = "Xamarin Blue",
BackgroundColor = Color.FromHex("#2c3e50"),
HeightRequest = 100,
HorizontalOptions = LayoutOptions.Center
};
customEditor = new Editor { Text = "Default starting text", HorizontalOptions = LayoutOptions.Center };
customEditor.Focused += StyledEntry_Focused;
layout.Children.Add(customEditor);
centerText = new Editor
{
IsEnabled = false,
Text = "This is a disabled editor",
HorizontalOptions = LayoutOptions.Fill
};
layout.Children.Add(centerText);
this.Content = layout;
}
void StyledEntry_Focused(object sender, FocusEventArgs e)
{
var text = centerText.Text + "new ";
centerText.Text = text;
centerText.HorizontalOptions = LayoutOptions.Center;
}
}
您是否尝试过使用** FillAndExpand **属性? –