【发布时间】:2011-09-14 14:03:10
【问题描述】:
我有一个 Silverlight 应用程序,但我遇到了问题。
该页面在正常加载时效果很好 - 无论是通过网络浏览器还是安装到桌面时。 当有人点击刷新时,问题出现在浏览器中。
当他们点击刷新 (F5) 时没有加载数据,控件呈现但数据绑定的是空的。 他们有一个javascript错误出现在IE的底部。
网页错误详情
消息:未处理的错误 Silverlight 应用 提供价值 在“System.Windows.Data.Binding”上抛出 一个例外。 [行:74 位置:57] 在 MS.Internal.XcpImports.MethodEx(IntPtr ptr, 字符串名称, CValue[] cvData)
在 MS.Internal.XcpImports.MethodEx(依赖对象 obj,字符串名称)在 MS.Internal.XcpImports.DataTemplate_LoadContent(DataTemplate 模板)在 System.Windows.Controls.DataGridTemplateColumn.GenerateElement(DataGridCell 单元格,对象数据项)在 System.Windows.Controls.DataGrid.PopulateCellContent(布尔 isCellEdited,DataGridColumn 数据网格列、数据网格行 数据网格行,数据网格单元格 数据网格单元)在 System.Windows.Controls.DataGrid.AddNewCellPrivate(DataGridRow 行,DataGridColumn 列)在 System.Windows.Controls.DataGrid.CompleteCellsCollection(DataGridRow 数据网格行)在 System.Windows.Controls.DataGrid.GenerateRow(Int32 rowIndex,Int32 插槽,对象 数据上下文)在 System.Windows.Controls.DataGrid.InsertElementAt(Int32 插槽,Int32 行索引,对象项, DataGridRowGroupInfo 组信息, Boolean isCollapsed) 在 System.Windows.Controls.DataGrid.InsertRowAt(Int32 行索引)在 System.Windows.Controls.DataGridDataConnection.NotifyingDataSource_CollectionChanged(对象 发件人, NotifyCollectionChangedEventArgs e)
在 System.Windows.Data.PagedCollectionView.OnCollectionChanged(NotifyCollectionChangedEventArgs 参数)在 System.Windows.Data.PagedCollectionView.ProcessAddEvent(对象 addedItem, Int32 addIndex) 在 System.Windows.Data.PagedCollectionView.ProcessCollectionChanged(NotifyCollectionChangedEventArgs 参数)在 System.Windows.Data.PagedCollectionView.<.ctor>b_0(对象 发件人, NotifyCollectionChangedEventArgs 参数) 在 System.Collections.ObjectModel.ObservableCollection1.OnCollectionChanged(NotifyCollectionChangedEventArgs e) at System.Collections.ObjectModel.ObservableCollection1.InsertItem(Int32 索引,T 项)在 System.Collections.ObjectModel.Collection`1.Add(T 项目)在 MyProject.Silverlight.MyViewModel.b_3(对象 参数,GetDataCompletedEventArgs 事件参数)在 MyProject.Silverlight.WebServicesSVC.WebServicesClient.OnGetDataCompleted(对象 状态)行:1 字符:1 代码:0
如果 [Line: 74 Position: 57] 来自 xaml 文件,则错误是中间行:
<sdk:DataGridTemplateColumn Header="Edit Details">
<sdk:DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<Button Command="{Binding UpdateCommand, Source={StaticResource ViewModel}}" CommandParameter="{Binding}" Content="Update" />
</DataTemplate>
</sdk:DataGridTemplateColumn.CellTemplate>
</sdk:DataGridTemplateColumn>
即,[Button...] 行,位置 57 是“{Binding..}”在 Command= 中开始的位置。
-- 正如我所说,这只发生在使用 IE 的刷新按钮刷新页面时,并且每次在多台 PC 上都会发生。
其他细节: 互联网浏览器 8 客户端电脑:Windows XP 托管服务器:Windows Server 2005(如果没有 2005 则为 2003)。 银光 4
任何人都可以阐明什么是错误的吗?刷新处理与正常加载页面有何不同?
【问题讨论】:
-
刷新页面比第一次加载要快,所以可能是时间问题。你的数据来自哪里?它是如何填充的?
-
@jb 我写了一个非常小的 HelloWorld 来查看 Silverlight 是否正在做一些特殊的事情,而事实并非如此。 F5 确实正确地带来了我的数据。是否可以分享一些代码,以便我可以尝试复制问题?
-
该页面由几个 WCF 服务填充;我在应用程序中有几页,其中只有一个失败(确实有 4-5 次服务调用来拉回数据)。
-
我可以尝试发布一些代码,但它是一个非常大的项目,有几个数据库等。可能需要一段时间才能提取出复制问题的较小部分...
-
我用 Fiddler 做了一些测试,我可以确认 WCF 服务肯定会返回数据。它只是没有被渲染。
标签: silverlight data-binding silverlight-4.0 mvvm