Xamarin表格复制粘贴和粗体问题

时间:2020-03-11 10:45:35

标签: android xamarin xamarin.forms cross-platform

我试图加粗,复制粘贴xamarin标签文本。我的代码是分开工作的。两者不一起工作。这是我的密码。

文本粗体功能

public FormattedString GetBoldTextValue(string parameterText)

{

var boldFormat = "**";

var formatString = new FormattedString();

    while (!string.IsNullOrWhiteSpace(parameterText))
    {
        try
        {
            var boldIndex = parameterText.IndexOf(boldFormat);

            if (boldIndex >= 0)
            {
                if (boldIndex > 0)
                {
                    var t = parameterText.Substring(0, boldIndex);
                    formatString.Spans.Add(new Span() { Text = t });
                }
                parameterText = parameterText.Substring(boldIndex + 2);
                var next = parameterText.IndexOf(boldFormat);
                var t1 = parameterText.Substring(0, next);
                formatString.Spans.Add(new Span() { Text = t1, FontAttributes = FontAttributes.Bold });
                parameterText = parameterText.Substring(next + 2);
            }
            else
            {
                formatString.Spans.Add(new Span() { Text = parameterText });
                break;
            }
        }
        catch (Exception)
        {
            formatString = new FormattedString();
            break;
        }
    }
    return formatString;
}

,这是复制粘贴代码。我是从这个样本中得到的。

https://forums.xamarin.com/discussion/178864/crossclipboard-label-text-select-issue#latest

0 个答案:

没有答案
相关问题