Uno: TextBlock: Run Inlines not rendered within Span

Created on 23 Apr 2020  路  3Comments  路  Source: unoplatform/uno

Current behavior

This XAML...

<TextBlock><Span>Where <Italic>did</Italic> my text go?</Span></TextBlock>

...renders like this on Android, iOS, and WASM:

image

Expected behavior

It should look the same as UWP:

image

How to reproduce it (as minimally and precisely as possible)

  1. Copy XAML fragment into a new Uno project
  2. Run

Environment

Nuget Package: Uno.UI

Package Version(s): 2.3.0-dev.7

Affected platform(s):

  • [x] iOS
  • [x] Android
  • [x] WebAssembly
  • [ ] (untested) WebAssembly renderers for Xamarin.Forms
  • [ ] (untested) macOS
  • [ ] Windows
  • [ ] Build tasks
  • [ ] Solution Templates

Visual Studio:

  • [ ] 2017 (version: )
  • [x] 2019 (version: 16.6 Preview 3)
  • [ ] for Mac (version: )

Relevant plugins:

  • [ ] Resharper (version: )

Anything else we need to know?

Only <Run> items seem to be affected. <Bold>, <Underline>, and <Italic> are all preserved.

arecode-generation kinbug projectext

Most helpful comment

Thanks for the investigation! Indeed as you identified this is a parser problem, specifically a limitation of the Xaml parser we're currently using which doesn't handle the nested tags correctly.

The workaround for the moment is to define all the Inlines explicitly:

<TextBlock><Run>Where </Run> <Italic>did</Italic> <Run> my text go?</Run></TextBlock>

All 3 comments

Oh funny, adding it programmatically after InitializeComponent works.

textBlock1.Inlines.Add(
    new Span
    {
        Inlines =
        {
            new Run { Text = "Where " },
            new Italic
            {
                Inlines =
                {
                    new Run { Text = "did" }
                }
            },
            new Run { Text = " my text go?" }
        }
    });

Result:

image

Looks like an issue while parsing. This code...

var span = (Span)XamlReader.Load(
    "<Span xmlns=\"http://schemas.microsoft.com/winfx/2006/xaml/presentation\">Where <Italic>did</Italic> my text go?</Span>");
textBlock1.Inlines.Add(span);

...renders a bit more:

image

Thanks for the investigation! Indeed as you identified this is a parser problem, specifically a limitation of the Xaml parser we're currently using which doesn't handle the nested tags correctly.

The workaround for the moment is to define all the Inlines explicitly:

<TextBlock><Run>Where </Run> <Italic>did</Italic> <Run> my text go?</Run></TextBlock>
Was this page helpful?
0 / 5 - 0 ratings

Related issues

PylotLight picture PylotLight  路  3Comments

MartinZikmund picture MartinZikmund  路  3Comments

JanabiSoft picture JanabiSoft  路  3Comments

MelbourneDeveloper picture MelbourneDeveloper  路  3Comments

paulovila picture paulovila  路  3Comments