c# - 选择所有文本时的 Xamarin 条目光标位置
问题描述
当我的输入控件聚焦时,我选择所有文本。当文本超出输入控件的宽度时,文本的开头将被截断 - 如下图所示:
但是,我希望尾部被截断,如下所示:
<Entry x:Name="entryA" Focused="entry_Focused"/>
private void entry_Focused(object sender, FocusEventArgs e)
{
entryA.CursorPosition = 0;
entryA.SelectionLength = entryItem.Text.Length;
}
解决方案
通过使用Entry的PropertyChanged方法,可以在数据框中的数据发生变化时进行操作。
我写了一个小例子供大家参考:</p>
这是xaml代码:
<StackLayout>
<Entry x:Name="entryA" WidthRequest="100" HorizontalOptions="CenterAndExpand" PropertyChanged="entryA_PropertyChanged"></Entry>
</StackLayout>
下面是后台代码:
public partial class MainPage : ContentPage
{
public int len { get; set; }
public MainPage()
{
InitializeComponent();
}
private void entryA_PropertyChanged(object sender, PropertyChangedEventArgs e)
{
var en = sender as Entry;
if (en.Text != null && len != en.Text.Length)
{
entryA.CursorPosition = 0;
len = en.Text.Length;
}
}
}
推荐阅读
- apache-spark - 使用 Pyspark 插入时锁定配置单元表
- swift - 使 CAShapeLayer 和 CGPath 符合 Codable 或 NSCoding
- reactjs - 是否可能带有子页面的反应导航抽屉?
- mysql - 为什么 Laravel 在时间戳中存储不同的时间
- python - 从python清除内存缓存
- jenkins - Hw 从 Jenkins 等持续集成服务中自动提取构建指令
- javascript - jquery:无法通过标签获取嵌套元素并更改其html
- mongodb - 从数组中计算总和并对 mongodb 进行排序
- python - 我的 python 代码如何自动知道在 Excel 中停止在哪一行
- ios - 如何处理表视图单元格中的全部打开/全部关闭,每个单元格在 iOS Swift 中具有查看更多/查看更少选项