【问题标题】:Xamarin Forms app not loading spaces when rebuildXamarin Forms 应用程序在重建时不加载空格
【发布时间】:2021-11-17 04:47:32
【问题描述】:

嘿嘿开发者,

我的 Xamarin.Forms Android 应用程序遇到了一个有趣的问题。

我的 XAML 如下所示:

<Label>
    <Label.FormattedText>
        <FormattedString>
            <Span TextColor="red">This sentence contains&#160;</Span>
            <Span FontAttributes="Bold">a whole lot of&#160;</Span>
            <Span TextDecorations="Underline">formatted strings!</Span>
        </FormattedString>
    </Label.FormattedText>
</Label>

如您所见,我通过简单地使用 解决了 XAML 忽略末尾 标签 前面的空格的问题&amp;#160; 的 Unicode 值。

这里的问题是,一旦我重建整个应用程序(它在运行时通过 Hot Reload 工作),这些空间将被忽略。它不断产生输出:

This sentence containsa whole lot offormated strings!

使用xml:space="preserve"对此没有任何影响,而且这导致了另一个错误。

希望您对如何解决这个问题有任何想法。

提前致谢!

【问题讨论】:

  • 会不会是你缺少一个 x ?喜欢“Š”

标签: xaml xamarin.forms xamarin.android


【解决方案1】:

如何保留空格

为此,您必须使用 Span 的 Text 属性,如下所示

<Span TextColor="red" Text="This sentence contains "/>

为什么  在 HotReload 中工作?

我可以重现您有趣的问题。我的猜测是问题出在 HotReload 以及它是如何在幕后实现的。如果有时间,最好把issue发到github上。

【讨论】:

    猜你喜欢
    • 2020-10-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-08
    • 2016-06-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-12-05
    相关资源
    最近更新 更多