【问题标题】:Silverlight 4 ManagedRuntimeError 4004 Listbox Scrolling Image XamlParseExceptionSilverlight 4 ManagedRuntimeError 4004 列表框滚动图像 XamlParseException
【发布时间】: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


【解决方案1】:

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

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

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

【讨论】:

  • 感谢@Jeff,我苦苦挣扎了将近 4 天,您的解决方案对我有用。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-06-03
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-08-22
相关资源
最近更新 更多