Friday, August 17, 2012

VirtualizingStackPanel and TextWrapping bug? Windows Phone

VirtualizingStackPanel and TextWrapping bug? Windows Phone

I have a strange behaviour with VirtualizingStackPanel. I have a list with items that containst TextBlock with TextWrap="Wrap". Here is the code

<ListBox x:Name="messagesList"                      ItemsSource="{Binding Messages}" >                 <ListBox.ItemContainerStyle>                     <Style TargetType="ListBoxItem">                         <Setter Property="HorizontalContentAlignment" Value="Stretch" />                     </Style>                 </ListBox.ItemContainerStyle>                 <ListBox.ItemTemplate>                     <DataTemplate>                         <StackPanel>                             <toolkit:ContextMenuService.ContextMenu>                                 <toolkit:ContextMenu>                                 ...                                 </toolkit:ContextMenu>                             </toolkit:ContextMenuService.ContextMenu>                             <CheckBox Style="{Binding Own, Converter={StaticResource MsgTypeToStyle}}"                                         Tag="{Binding TimeString}"                                         IsEnabled="True">                                 <TextBlock Text="{Binding Content}" TextWrapping="Wrap"/>                             </CheckBox>                         </StackPanel>                     </DataTemplate>                 </ListBox.ItemTemplate>             </ListBox> 

It works pretty good, but if I try to scroll very fast (using mouse on emulator, not prommatically) there is some lagging in scroll, probably HorizontallOffset sometimes calculates wrong, and in the bottom in ends with very strange result (see image, right image demostrates normal behaviour). scroll bug

After research i figured out that problem in combination VirtualizingStackPanel and TextBlock.TextWrap="Wrap", if i remove one element from this couple all works correctly.

But i need virtualization, because of big items count, and TextWrap for correct text displaying.

So i thing about implementing my own realisation of Virtualizing Panel, can you please guide me, how to do this, or how to fix current problem?

Thanks.

UPD: The problem: on the first two images ListBox are already(!) scrolled to the bottom(it can't be scrolled down any more), but elements placed incorrectly, correct placing on the right image. This happens only if you will scroll very fast

P.S. thanks for good luck wishes;)

Answers & Comments...

Answer: 1

What is the problem on 2nd screen? You mean large empty space after last message? Last message not being put at the bottom of page? Am I getting this right?

Actually i didn't try to reproduce your code and bug but my point is that since you are using 3rd party libs (Silverlight Toolkit) in your app, why not to use Coding4Fun Tools as well?

I wrote this dummy class:

public class Message {     public string Time { get; private set; }     public string Content { get; private set; }      public Message(string time, string content)     {         Time = time;         Content = content;     } } 

Then i put this dummy code in main page constructor:

var _messages = new ObservableCollection<Message>();  for (int i = 0; i < 50; i++) {     _messages.Add(new Message("12:40", "Teh very long string which should be wrapped. Pavel Durov gives WP7 Contest winners less money than he did for Android/iOS winners. FFFUUUUUUUUUUUUUU ")); }  this.ListBox.ItemsSource = _messages; 

And in xaml i put a listbox with chat bubble control of toolkit:

<ListBox x:Name="ListBox">     <ListBox.ItemTemplate>         <DataTemplate>             <c4fToolkit:ChatBubble>                 <Grid>                     <Grid.RowDefinitions>                         <RowDefinition Height="Auto"/>                         <RowDefinition Height="Auto"/>                     </Grid.RowDefinitions>                     <TextBlock Grid.Row="0"                                Text="{Binding Content}"                                TextWrapping="Wrap"/>                     <TextBlock Grid.Row="1"                                Text="{Binding Time}"                                HorizontalAlignment="Right"/>                 </Grid>             </c4fToolkit:ChatBubble>         </DataTemplate>     </ListBox.ItemTemplate> </ListBox> 

I ran it and saw no strange behaviours, maybe little bit of lagging. There is the result:

dat pic is huge

Hope i did some help.


Удачи с конкурсом, я б сам поучаствовал, но не верю, что за 1,5 месяца удастся сделать приличный клиент.

Answer by kvas for VirtualizingStackPanel and TextWrapping bug? Windows Phone




No comments:

Post a Comment

Send us your comment related to the topic mentioned on the blog