View Issue Details

IDProjectCategoryView StatusLast Update
0001842NoesisGUIC# SDKpublic2020-11-26 13:17
Reporterai_enabled Assigned Tosfernandez  
PrioritynormalSeverityminor 
Status resolvedResolutionno change required 
Product Version3.0.6 
Summary0001842: Text in Grid is not trimmed properly
Description

Hi guys,

here is a snippet for XamlToy:


<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Background="Black">

<Grid Background="White"
HorizontalAlignment="Left"
Width="300">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>

    <TextBlock
        Text="Some very long text here"
        Foreground="Red"
        FontSize="24"
        LineHeight="24"                            
        TextWrapping="NoWrap"
        TextTrimming="CharacterEllipsis" 
        HorizontalAlignment="Left" />

    <TextBlock
        Grid.Column="1"
        Text="[IMPORTANT]"
        Foreground="Blue"
        FontSize="24"
        LineHeight="24"                            
        TextWrapping="NoWrap"
        TextTrimming="None" 
        HorizontalAlignment="Left" />
</Grid>

</Grid>

Only (only!) if you replace Auto with * for the first column the text there will be trimmed properly.
My intention is to make the second column primary (as there is some important control) so the first column will trim but I cannot achieve this

Regards!

PlatformAny

Activities

ai_enabled

ai_enabled

2020-11-26 00:32

updater   ~0006821

Surprisingly, it's also failing in WPF as I've just tested.

ai_enabled

ai_enabled

2020-11-26 00:48

updater   ~0006822

The workaround I've found: (works in both NoesisGUI and WPF)


<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Background="Black">
<DockPanel Background="White"
HorizontalAlignment="Left"
Width="300">
<TextBlock
Text="[IMPORTANT]"
Foreground="Red"
FontSize="24"
LineHeight="24"
TextWrapping="NoWrap"
TextTrimming="CharacterEllipsis"
HorizontalAlignment="Left"
DockPanel.Dock="Right" />

    <TextBlock
        Text="Some very long text here"
        Foreground="Blue"
        FontSize="24"
        LineHeight="24"
        TextWrapping="NoWrap"
        TextTrimming="CharacterEllipsis"
        HorizontalAlignment="Left"
        DockPanel.Dock="Left" />
</DockPanel>

</Grid>

Interestingly, if I swap elements (while keeping their DockPanel.Dock properties) the issue appears again. It seems the order of TextBlock inside the panel matters!

sfernandez

sfernandez

2020-11-26 10:14

manager   ~0006823

In the case of the Grid the behavior is totally expected, you defined the first column to be Auto, allowing the first TextBlock to grow as much as it needs to fit all the text, so no trimming is possible.
And if you change the first column to *, then you have 2 columns of the same size (150 each because the Grid has a fixed 300 width).

In the case of the DockPanel the behavior is also as expected because DockPanel allocates the space required by its children in order.
If first child is positioned to the right, then it will use the remaining space on the left to position the rest of children.
If you change the order and first child is docked to the left, then the remaining space on the right will be used for the rest of children.

You can achieve the same result as with the working DockPanel layout by using a Grid with the second column set to Auto:

<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Background="Black">

<Grid Background="White"
HorizontalAlignment="Left"
Width="300">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

    <TextBlock
        Text="Some very long text here"
        Foreground="Red"
        FontSize="24"
        LineHeight="24"                            
        TextWrapping="NoWrap"
        TextTrimming="CharacterEllipsis" 
        HorizontalAlignment="Left" />

    <TextBlock
        Grid.Column="1"
        Text="[IMPORTANT]"
        Foreground="Blue"
        FontSize="24"
        LineHeight="24"                            
        TextWrapping="NoWrap"
        TextTrimming="None" 
        HorizontalAlignment="Left" />
</Grid>

</Grid>

ai_enabled

ai_enabled

2020-11-26 12:30

updater   ~0006825

Last edited: 2020-11-26 12:32

Thank you for a great explanation, Sergio!
Your code snippet works great! I've tried it yesterday (among dozens of other ideas) and my mistake was that Grid had HorizontalAlignment="Stretch" so it resulted in the first column being too wide (so the label from the second column appeared too far away from the short text in the first column).
So I've assumed that "Auto" for the first column must trim the text as the grid obviously have a width limitation and the second column should have priority due to * width.
I realize it's a nuance of WPF but heck it's quite a non-intuitive and frustrating one—so much that I've actually created a report this time to check whether it's the correct behavior.
BTW, many other cases when it frustrated me before were when I tried to use horizontal StackPanel to combine text entries (as it's way easier than putting them into a grid and defining columns). WPF has its downsides and only through painful experience I can learn the right way.

You can close this ticket unless you're planning to break WPF compatibility for the good! :-)
Regards!

sfernandez

sfernandez

2020-11-26 13:17

manager   ~0006826

We'll stick to WPF behavior :)

Issue History

Date Modified Username Field Change
2020-11-26 00:30 ai_enabled New Issue
2020-11-26 00:32 ai_enabled Note Added: 0006821
2020-11-26 00:48 ai_enabled Note Added: 0006822
2020-11-26 10:14 sfernandez Assigned To => sfernandez
2020-11-26 10:14 sfernandez Status new => feedback
2020-11-26 10:14 sfernandez Note Added: 0006823
2020-11-26 12:30 ai_enabled Note Added: 0006825
2020-11-26 12:30 ai_enabled Status feedback => assigned
2020-11-26 12:32 ai_enabled Note Edited: 0006825
2020-11-26 13:17 sfernandez Status assigned => resolved
2020-11-26 13:17 sfernandez Resolution open => no change required
2020-11-26 13:17 sfernandez Note Added: 0006826