如何在Xamarin.Forms中创建多行TextBox

Nir*_*hta 15 xamarin xamarin.forms

如何在Xamarin.Forms中创建多行TextBox?

通过一些研究,我发现可以<Editor>使用自定义字体大小和样式的XAML页面中的标记完成,但创建中心对齐的文本.但是我想从左上角开始游标和文本.

Ven*_*ari 12

编辑器用于收集预计需要多行的文本.例:

<?xml version="1.0" encoding="UTF-8"?>
<ContentPage xmlns="http://xamarin.com/schemas/2014/forms" 
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml" 
x:Class="TextSample.EditorPage"
Title="Editor">
    <ContentPage.Content>
        <StackLayout>
            <Editor Text="Editor is used for collecting text that is expected to take more than one line." BackgroundColor="#2c3e50" HeightRequest="100" />
        </StackLayout>
    </ContentPage.Content>
</ContentPage>
Run Code Online (Sandbox Code Playgroud)


Dav*_*sus 7

您可以使用Editor以下代码并指定最大字符数:

<Editor Keyboard="Plain" AutoSize="TextChanges" MaxLength="180" />
Run Code Online (Sandbox Code Playgroud)

注意:使用AutoSize="TextChanges"编辑器将更改大小以适应用户输入的内容。默认情况下,自动调整大小处于关闭状态。


Pat*_*ode 5

您提到的编辑器,像这样编码(来自页面的示例)不会创建居中的文本

  <StackLayout Padding="5,10">
        <Editor>
            <Editor.BackgroundColor>
                <OnPlatform x:TypeArguments="x:Color"
                    iOS="#a4eaff"
                    Android="#2c3e50"
                    WinPhone="#2c3e50" />
            </Editor.BackgroundColor>
        </Editor>
    </StackLayout>
Run Code Online (Sandbox Code Playgroud)