Silverlight 4 ManagedRuntimeError 4004 Listbox Scrolling Image XamlParseException
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}"
开发者_如何学C HorizontalAlignment="Center" />
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Controls:Expander>
Im totally lost. Any help would be greatly appreciated.
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.
精彩评论