Olivier La Haye
Olivier La Haye

Reputation: 13

Text trimming with column definition with star in wpf

In my second grid where I have a column definition at Width="800" I would like to have something responsive like 1* and my text would trim accordingly to the size of actual width of the grid column.

For example:

I have an image 40x40 pixels in the first column with my text. My text would be long, let's say 1000 pixels

if my overall grid width is 1000 pixels.

I would have 200 pixels in the second column and 800 pixels in the first, that would make my text trim at 800 - 40 pixel = 760 pixel

if my overall grid width is 500 pixels.

I would have 100 pixels in the second column and 400 pixels in the first, that would make my text trim at 400 - 40 pixel = 360 pixel,

etc.

     <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="4*" />
                <ColumnDefinition Width="1*" />
            </Grid.ColumnDefinitions>
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="800" /> <!--Instead of 800 I want to put 1*-->
                </Grid.ColumnDefinitions>
                <Image
                    Height="40"
                    Margin="7"
                    Source="{Binding FileIcon}"/>
                <TextBlock
                    Grid.Column="1"
                    HorizontalAlignment="Left"
                    VerticalAlignment="Center"
                    Text="{Binding SomeLongText}"
                    TextTrimming="CharacterEllipsis" />
            </Grid>
            <!--<Grid Grid.Column="1"> Other stuff here responsive </Grid>-->
    </Grid>

Can you help?

Thanks, Olivier

Upvotes: 0

Views: 165

Answers (0)

Related Questions