Adam Goodchild
Adam Goodchild

Reputation: 61

Using TextWraping within a TextBox, inside a Grid for use within a ListBox in WP7

I am trying to get my data to display properly within a GridLayout, which is to be used as a DataTemplate for an Item within ListBox. Here is the code associated with what I am doing:

<Grid Name="FeedItemTemplate">
    <Grid.RowDefinitions>
    <RowDefinition Height="Auto" />
    <RowDefinition Height="Auto" />
</Grid.RowDefinitions>

<Grid.ColumnDefinitions>
    <ColumnDefinition Width="Auto" />
    <ColumnDefinition Width="*" />
    <ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>

<Image Source="{Binding ProfileImage}" Grid.RowSpan="2" Height="75" Width="75" VerticalAlignment="Center" Margin="1" />
<TextBlock Text="{Binding UserName}" Grid.Column="1" Foreground="#FFC8AB14" FontSize="28" HorizontalAlignment="Left"/>
<TextBlock Text="{Binding TimeStamp}" Grid.Column="2" TextWrapping="Wrap" FontSize="18" HorizontalAlignment="Center"/>
<TextBlock Text="{Binding Message}" Grid.Column="1" Grid.Row="1" Grid.ColumnSpan="2" TextWrapping="Wrap" FontSize="24" />
</Grid>

The issue is that using this layout, when TextWrapping is set to Wrap, the Item is displayed correctly, but when scrolling through the ListBox everything is really jittery, you cannot scroll in small increments, and it just jumps all over the place.

Any reason why it does this? As I said, only when TextWrapping is set to Wrap it does this. When its not used, it scrolls fine, but the text is all along one line and off the screen.

Upvotes: 2

Views: 629

Answers (3)

Mick N
Mick N

Reputation: 14882

This is a known issue with listbox scrolling in the current ctp when you have variable height items. The workaround for now is to set a fixed height on your listbox item content. You'll probably also notice the scroll bar doesnt properly go to the bottom all the time. The workaround fixes that too.

Reference.

Upvotes: 0

Andr&#233;as Saudemont
Andr&#233;as Saudemont

Reputation: 1353

For some reason that I do not fully understand, settings the ListBox's ItemsPanel property to a StackPanel might solve your problem:

<UserControl.Resources>
    <ItemsPanelTemplate x:Key="MyItemsPanelTemplate">
        <StackPanel/>
    </ItemsPanelTemplate>
</UserControl.Resources>

...

<ListBox ... ItemsPanel="{StaticResource MyItemsPanelTemplate}"/>

Upvotes: 1

Andr&#233;as Saudemont
Andr&#233;as Saudemont

Reputation: 1353

Does it keep jumping if you explicitly set the top-level Grid element's width to a fixed size?

Upvotes: 1

Related Questions