作为iPhone
的iMessenger,我正在设计一个布局。
在Textbox中,我使用Editor输入文本。
在iPhone
的iMessenger应用上,Editor
可以以TailTruncation
模式显示
====
我搜索了一下,没有发现类似于Label
的LineBreakMode的Editor
属性。
如何在Xamarin forms
上用Editor
的TailTruncation
模式显示文本
请帮帮我!
发布于 2019-09-28 14:18:29
您也许能够在Editor上使用Converter来实现TailTruncation
。如下所示:
public class FullToShortConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
{
string fullText = (string)value;
string tempString = "";
if (string.IsNullOrWhiteSpace(fullName)) {
return string.Empty;
}
if (parameter == null) { // You can pass desired string length as a parameter
// Assuming you want a string of length 10.
// Then 0..6 is 7 chars + three dots
// There is no sense in changing the last 3 letters with ellipsis
tempStr = fullText.Length > 10 ? fullText.Substring(0, 6) + "..." : fullText;
} else {
int maxChars = (int)parameter;
tempStr = fullText.Length > maxChars ? fullText.Substring(0, maxChars - 3) + "..." : fullText;
}
return tempStr;
}
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
{
throw new InvalidCastException("Should never come here");
}
}
如果您想在用户与编辑器交互时显示/隐藏全文,则需要在Focused
和Unfocused
事件中处理此问题。
https://stackoverflow.com/questions/58138388
复制相似问题