Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF layout for autosize textblock and icon floating on the right - how?
    primarykey
    data
    text
    <p>I am trying to get a layout where an icon floats on the right end of a textblock; the textblock grows/shrinks to content. I cannot make this happen without the textblock running outside the grid. For example:</p> <pre><code>&lt;Grid x:Name="LayoutRoot" Width="500" HorizontalAlignment="Left" ShowGridLines="True" &gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="Auto" /&gt; &lt;ColumnDefinition Width="40"/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;TextBlock x:Name="textBlock" VerticalAlignment="Top" Height="25" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis" Grid.Column="0" &gt; &lt;TextBlock.Text&gt;longer keeps going and going testgrand you going and then t &lt;/TextBlock.Text&gt; &lt;/TextBlock&gt; &lt;Rectangle Fill="#FFDE3030" Stroke="Black" VerticalAlignment="Top" Height="41" Width="41" Grid.Column="1"/&gt; &lt;/Grid&gt; </code></pre> <p>Seems like the natural approach and works fine when the text is shorter than the column/grid, except the textbox and column will grow indefinitely and not honor the bounds of the grid. </p> <p>The inverse, with the icon on the left, works fine with a simpler layout, and the textblock doesn’t grow indefinitely. This is achieved with this markup: </p> <pre><code>&lt;Grid Grid.Row="1" Width="500" HorizontalAlignment="Left"&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="40" /&gt; &lt;ColumnDefinition /&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Rectangle Fill="#FFDE3030" Stroke="Black" VerticalAlignment="Top" Height="41" Width="41" Grid.Column="0"/&gt; &lt;TextBlock x:Name="textBlock2" VerticalAlignment="Top" Height="25" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis" Grid.Column="1" HorizontalAlignment="Left"&gt; &lt;TextBlock.Text&gt;longer testgrow the textblock and it will just keep growing but it will stop when it gets too &lt;/TextBlock.Text&gt; &lt;/TextBlock&gt; &lt;/Grid&gt; </code></pre> <p>Any help appreciated. If a grid won’t work, is there an alternate layout where I can get the icon floating on the right of the text, and the textblock will trim text when it’s too long?</p> <p>Also:</p> <ul> <li><p>No, using * size columns doesn't work because the columns are fixed, and the icon won't float at the end of the text</p></li> <li><p>A DockPanel doesn't work either, or at least I or others I've asked haven't been able to. The best it can do is to have the icon half-cut-off outside the dockpanel's right side.</p></li> </ul>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload