我正在创建一个移动应用程序,因为当用户创建该类型的消息时,我需要发送询问或支持的消息,然后单击返回或从键盘输入高度完成调整后,如果用户点击背面,则还应对其进行管理。在那,我无法使用Editor
控件。我正在使用共享项目来开发应用程序。
我尝试以下代码:
sample.xaml
<StackLayout Padding="50" HeightRequest="150">
<Entry TextChanged="Entry_TextChanged" x:Name="EntryCustom"/>
</StackLayout>
sample.xaml.cs
private void Entry_TextChanged(object sender, TextChangedEventArgs args)
{
int isElse = 0;
if (args != null && args.OldTextValue != null && args.NewTextValue != null)
{
string[] oldval = args.OldTextValue.Split('r');
string[] Newval = args.NewTextValue.Split('r');
if (oldval.Count() > Newval.Count())
{
EntryCustom.HeightRequest = EntryCustom.HeightRequest - 33;
isElse = 2;
}
else
isElse = 1;
}
if (args.OldTextValue != null && (args.NewTextValue == "n" || args.NewTextValue.EndsWith("r")) && EntryCustom.HeightRequest < 100 && (isElse == 1 || args != null || args.OldTextValue.Count() > args.NewTextValue.Count()))
EntryCustom.HeightRequest = EntryCustom.HeightRequest + 33;
}
任何人都可以研究一下,建议我必须在代码中更改什么?
您应该使用编辑器。使用<Editor AutoSize="TextChanges"/>
,编辑器将根据输入的文本调整大小。