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>
我完全迷路了。任何帮助将不胜感激。