Home > OS >  Xamarin Forms app not loading spaces when rebuild
Xamarin Forms app not loading spaces when rebuild

Time:09-28

Heyho developers,

I'm experiencing an interesting problem with my Xamarin.Forms Android application.

My XAML looks like this:

<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>

As you see, I've solved the problem of XAML ignoring spaces in front of end tags by simply using the Unicode value of &#160;.

The problem here is, once I rebuild the whole application (it works via Hot Reload while it's running) these spaces are being ignored. It keeps producing the output:

This sentence containsa whole lot offormated strings!

Using xml:space="preserve" didn't have any effect on that, furthermore this led to another error.

Hope you got any ideas on how to solve this.

Thanks in advance!

CodePudding user response:

How to preserve spaces

For this you will have to use the Text property of Span as follows

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

Why &#160; works in HotReload?

I could reproduce your interesting issue. My guess is that the problem is with the HotReload and how it is implemented behind the scenes. If you have time, it would be great if you post the issue in github.

  • Related