【发布时间】:2010-08-04 08:13:48
【问题描述】:
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 崩溃。
仅当我在项目模板中包含内容控件、内容演示器或图像控件时才会出现该错误。例如,如果我将“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>
我完全迷路了。任何帮助将不胜感激。
【问题讨论】:
-
我破解了一个解决方案。我禁用了列表框的滚动查看器,然后将列表框包装在一个独立的滚动查看器中。我的直觉告诉我问题出在 ItemsControllGenerator 上。具体来说,当列表框尝试虚拟化我的内容时,出现了问题。
-
您应该将此作为答案发布 - 这可能是一种黑客/解决方法,但如果这是我们所拥有的,那么它是值得的。 (我也有滚动导致崩溃的问题 - 你使用 Silverlight 工具包吗?)
-
好的,伙计们。它可能正在工作。但是 ListBox 中的大约 1000 个元素呢?
标签: silverlight listbox scroll xamlparseexception