Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 933063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T20:46:15+00:00 2026-05-15T20:46:15+00:00

I am trying to get a layout where an icon floats on the right

  • 0

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:

<Grid x:Name="LayoutRoot" Width="500" HorizontalAlignment="Left" ShowGridLines="True" >
 <Grid.ColumnDefinitions>
  <ColumnDefinition Width="Auto" />
  <ColumnDefinition Width="40"/>
 </Grid.ColumnDefinitions>
   <TextBlock x:Name="textBlock" VerticalAlignment="Top" Height="25" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis" Grid.Column="0" >
  <TextBlock.Text>longer keeps going and going testgrand you going and then t 
</TextBlock.Text>
  </TextBlock>
<Rectangle Fill="#FFDE3030" Stroke="Black" VerticalAlignment="Top" Height="41" Width="41" Grid.Column="1"/>
</Grid>

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.

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:

<Grid Grid.Row="1" Width="500" HorizontalAlignment="Left">
<Grid.ColumnDefinitions>
  <ColumnDefinition Width="40" />
  <ColumnDefinition />
  </Grid.ColumnDefinitions>
  <Rectangle Fill="#FFDE3030" Stroke="Black" VerticalAlignment="Top" Height="41"  Width="41" Grid.Column="0"/>
  <TextBlock x:Name="textBlock2" VerticalAlignment="Top" Height="25" TextWrapping="NoWrap" TextTrimming="CharacterEllipsis" Grid.Column="1" HorizontalAlignment="Left">
  <TextBlock.Text>longer testgrow the textblock and it will just keep growing but it will stop when it gets too </TextBlock.Text>
 </TextBlock>
</Grid>

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?

Also:

  • No, using * size columns doesn’t work because the columns are fixed, and the icon won’t float at the end of the text

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

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T20:46:15+00:00Added an answer on May 15, 2026 at 8:46 pm

    Someone internally suggested this answer, which works:

        <WrapPanel HorizontalAlignment="Left" VerticalAlignment="Top">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*" />
                    <ColumnDefinition Width="10" />
                </Grid.ColumnDefinitions>
                <AccessText TextTrimming="CharacterEllipsis" Grid.Column="0" Margin="0,0,4,0" Text="type more typingon the long hi longer than what if you keep tyingin and get to the end and that's why it changed because you were in the middle" />
                <Border Grid.Column="1" Width="10" Height="10" Background="Red" />
            </Grid>
        </WrapPanel>
    

    The wrappanel seems to provide the necessary magic. I haven’t tried Quartermeister’s but will save it for future reference!

    Our final layout is more complicated and looks like this (it’s the header bar for an expander):

    <WrapPanel Orientation="Vertical">
        <Grid x:Name="HeaderSite" >
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="19" />
                <ColumnDefinition Width="16" />
                <ColumnDefinition Width="Auto" />
                <ColumnDefinition />
                <ColumnDefinition Width="Auto" /> <!-- 7/14: fix from list: wrap the whole thing in a wrappanel. Allows for one * col. -->
                <ColumnDefinition Width="19" />
            </Grid.ColumnDefinitions>
            <ToggleButton  x:Name="buttonExpanderToggleButton"
                Height="20" VerticalAlignment="Top"
                    />
            <Image x:Name="imageActivityIcon" Grid.Column="1"
                Height="16" Width="16" 
                HorizontalAlignment="Left" VerticalAlignment="Top" 
                Margin="0"/>
    
            <AccessText x:Name="textActivityID" 
                Grid.Column="2"
                VerticalAlignment="Top" Margin="5,2,0,0" 
                TextTrimming="CharacterEllipsis"
                FontSize="12" HorizontalAlignment="Left" Text="MA77777"/>
            <AccessText x:Name="textActivityHeader" 
                Grid.Column="3"
                VerticalAlignment="Top" Margin="0,2,0,0" 
                TextTrimming="CharacterEllipsis"
                FontSize="12" HorizontalAlignment="Left" Text="Title title title title aand Title title title title a little and if you type more what happens as you keep typing "/>
            <AccessText x:Name="textActivityStatus" 
                FontWeight="Normal" 
                FontStyle="Italic" 
                Grid.Column="4"
                TextTrimming="CharacterEllipsis"
                VerticalAlignment="Top" Margin="0,2,8,0"
                FontSize="12" HorizontalAlignment="Left" Text="(On Hold)"/>
            <Image x:Name="imageLink" 
                Stretch="None" VerticalAlignment="Top" HorizontalAlignment="Left" Grid.Column="5"/>
        </Grid>
    </WrapPanel>
    

    This works fine too even with the other auto sized columns. The key seems to be the wrappanel and the one * sized column. If you set them all to auto it doesn’t work.

    I hope this and Quartermeister’s answer helps somebody, because this drove me #$%#$% crazy.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to get a layout to look like this : (source: yfrog.com )
I'm trying to get this css layout to work with IE7 and I'm a
I'm trying to get a simple solution for this layout. This is the simplified
I'm trying to get get a vertical, top-aligned layout to work. This is what
I am trying to write my thesis in latex... Cannot get the layout straight
I'm trying to get the following layout: Link to Image And this is what
I am trying to get a layout that always takes up the entire screen,
So I'm trying to get a navigation layout for a header like the one
I'm battling with Android's awful layout system. I'm trying to get a table to
I can't get my divs to layout properly. I'm trying to have a top

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.