Adrian
Adrian

Reputation: 20058

Auto size TextBlock

I have the following ListView:

<ListView Name="listView1" Grid.Row="1" ItemsSource="{Binding Items}" >
     <ListView.ItemTemplate>
          <DataTemplate>
              <StackPanel>
                  <TextBlock Text="{Binding Title}" />
                  <TextBlock Text="{Binding Content}"  />
                  <TextBlock Text="{Binding Link}" FontSize="18" />
              </StackPanel>
           </DataTemplate>
      </ListView.ItemTemplate>
</ListView>

My problem is with the TextBlock cantaining the Content. If the text exceeds the width of the screen I want the remaining text to appear on the second row of the TextBlock.

Is this possible with a TextBlock ?

Thanks.

Upvotes: 1

Views: 2428

Answers (2)

StaWho
StaWho

Reputation: 2488

Use TextWrapping property

<ListView Name="listView1" Grid.Row="1" ItemsSource="{Binding Items}" >
            <ListView.ItemTemplate>
                <DataTemplate>
                    <StackPanel>
                        <TextBlock Text="{Binding Title}" FontSize="30" Foreground="#24FF2E" />
                        <TextBlock TextWrapping="Wrap" Text="{Binding Content}" FontSize="18" Foreground="#D1D8E8" />
                        <TextBlock Text="{Binding Link}" FontSize="18"  Foreground="#009FFF"/>
                    </StackPanel>
                </DataTemplate>
            </ListView.ItemTemplate>
        </ListView>

Upvotes: 3

Adam
Adam

Reputation: 15805

Just set the TextWrapping property, like so:

<TextBlock TextWrapping="Wrap"></TextBlock>

Upvotes: 4

Related Questions