Silverlight 4 ManagedRuntimeError 4004 列表框滚动图像 XamlParseException
Silverlight 4 让我崩溃了。即时调试器说:
An unhandled exception ('Unhandled Error in Silverlight Application')
Code: 4004
Category: ManagedRuntimeError
Message: System.Windows.Markup.XamlparseException: [Line: 0 Position: 0]
我将一个列表框绑定到 20 个(左右)项目的集合。该集合加载良好并正确绑定。然而,当我滚动到集合的底部,然后尝试向上滚动 silverlight 崩溃。
仅当我在项目模板中包含 contentcontrol、contentpresenter 或图像控件时,才会发生该错误。例如,如果我将“InnerBorder”高度设置为 100 并删除内容控件 silverlight 将不会崩溃。此外,{Binding Visual} 是在项目的视图模型上定义的图像。
这是我的代码。
<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>
我完全迷失了。任何帮助将不胜感激。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我也遇到了同样的问题。我设法将其追踪到
ToolTipService
。如果我在显示工具提示时滚动,则会发生崩溃(仅在某些项目上)。如果我删除工具提示绑定,这个问题就会消失。我还没有解决这个问题,以便可以显示工具提示,但至少我可以消除崩溃。
更新
我设法解决了问题并保持工具提示正常工作。和你一样,我直接将工具提示内容设置为一些文本。相反,我实际上将内容设置为包含
TextBlock
的 StackPanel,然后该文本块包含文本,现在它可以正常工作而不会崩溃。不幸的是,我不完全确定为什么这会起作用。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 aTextBlock
that then contained the text and now it works without crashing. I am not entirely sure why this works, unfortunately.