2

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>

我完全迷路了。任何帮助将不胜感激。

4

1 回答 1

2

我遇到了同样的问题。我设法将其追踪到ToolTipService. 如果我在显示工具提示时滚动,则会发生崩溃(仅在某些项目上)。如果我删除工具提示绑定,这个问题就会消失。

我还没有解决这个问题,以便可以显示工具提示,但至少我可以消除崩溃。

更新
我设法解决了问题并保持工具提示正常工作。像你一样,我直接将工具提示内容设置为一些文本。相反,我实际上将内容设置为StackPanel包含 aTextBlock然后包含文本的内容,现在它可以正常工作而不会崩溃。不幸的是,我不完全确定为什么会这样。

于 2011-04-26T14:47:03.610 回答