2

Silverlight 4 is crashing on me. The Just-In-Time Debugger says:

An unhandled exception ('Unhandled Error in Silverlight Application')

Code: 4004

Category: ManagedRuntimeError

Message: System.Windows.Markup.XamlparseException: [Line: 0 Position: 0]

I bind a listbox to a collection of 20 (or so) items. the collection loads fine and binds correctly. However, when I scroll to the bottom of the collection and then try to scroll back up silverlight crashes.

The error only occurs when I include a contentcontrol, contentpresenter, or an image control within my Item Template. For instance, If I set the 'InnerBorder' height to 100 and remove the content control silverlight will not crash. Furthermore The {Binding Visual} is a image defined on the item's view model.

Here is my code.

  <Border HorizontalAlignment="Left"
            Margin="2"
            Padding="0">
        <Controls:Expander ExpandDirection="Right"
                           Header="Templates">                
            <ListBox UseLayoutRounding="False" 
                     SelectedItem="{Binding SelectedTemplate, Mode=TwoWay}"
                     Margin="4"
                     ItemsSource="{Binding Templates}"
                     ScrollViewer.VerticalScrollBarVisibility="Visible"
                     Width="250">
                <ListBox.ItemTemplate>
                    <DataTemplate>
                        <Border Style="{StaticResource InnerBorder}"
                                Width="200"
                                Margin="4">
                            <ToolTipService.ToolTip>
                                <ToolTip Content="{Binding Description}" />
                            </ToolTipService.ToolTip>
                            <StackPanel Orientation="Vertical"
                                        VerticalAlignment="Center"
                                        HorizontalAlignment="Center">

                                <ContentControl Content="{Binding Visual}"
                                                MaxWidth="100" />

                                <TextBlock Text="{Binding Name}"
                                           HorizontalAlignment="Center" />
                            </StackPanel>
                        </Border>
                    </DataTemplate>
                </ListBox.ItemTemplate>
            </ListBox>
        </Controls:Expander>

Im totally lost. Any help would be greatly appreciated.

Arturs
  • 1,258
  • 5
  • 21
  • 28
Torak
  • 83
  • 6
  • 1
    I hacked a solution. I disabled the listbox's scroll viewer and then wraped the listbox within an independent scroll viewer. My gut tells me the problem lies in the ItemsControllGenerator. Specifically, something is going bad as the listbox attempts to virtualize my content. – Torak Aug 04 '10 at 17:31
  • You should post this as an answer - it may be a hack/workaround but if it's all we have, then it's worth it. (I too have a problem with scrolling causing a crash - do you use the Silverlight Toolkit?) – Jeff Yates Apr 26 '11 at 13:24
  • Ok, guys. It's may be working. But what about ~1000 elements in ListBox? – Monochromie Jun 26 '11 at 19:10

1 Answers1

2

I was having this same issue. I managed to track it down to the ToolTipService. If I scroll while a tooltip is displayed, the crash occurs (only on some items). If I remove the tooltip binding, this issue goes away.

I have not yet resolved that problem so that tooltips can be displayed, but at least I can remove the crash.

Update
I managed to resolve the problem and keep tooltips working. Like you, I was directly setting the tooltip content to some text. Instead, I actually set the content to a StackPanel containing a TextBlock that then contained the text and now it works without crashing. I am not entirely sure why this works, unfortunately.

Jeff Yates
  • 61,417
  • 20
  • 137
  • 189