【问题标题】:How to create multiline TextBox in Xamarin.Forms如何在 Xamarin.Forms 中创建多行文本框
【发布时间】:2023-03-15 00:26:01
【问题描述】:

如何在 Xamarin.Forms 中创建多行文本框?

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

【问题讨论】:

  • 您应该放置一些或您的代码,例如编辑器及其父级。一个没有任何属性但高度的编辑器,是多行的,默认情况下不居中
  • 在传统的 Xamarin 中,您只需在属性中选择 inputType 到 textMultiLine 即可。

标签: xamarin xamarin.forms


【解决方案1】:

编辑器用于收集预计超过一行的文本。 示例:

<?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>

【讨论】:

    【解决方案2】:

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

      <StackLayout Padding="5,10">
            <Editor>
                <Editor.BackgroundColor>
                    <OnPlatform x:TypeArguments="x:Color"
                        iOS="#a4eaff"
                        Android="#2c3e50"
                        WinPhone="#2c3e50" />
                </Editor.BackgroundColor>
            </Editor>
        </StackLayout>
    

    【讨论】:

      【解决方案3】:

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

      <Editor Keyboard="Plain" AutoSize="TextChanges" MaxLength="180" />
      

      注意:使用AutoSize="TextChanges",编辑器将更改大小以适应用户输入时的输入。自动调整大小默认关闭。

      【讨论】:

        猜你喜欢
        • 2017-04-06
        • 2020-09-24
        • 2019-10-28
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多