在 Silverlight 3 中使用 DataGrid 绑定到 DomainDataSource
使用标记,我无法获取要在网格中显示的数据:
<riacontrols:DomainDataSource x:Name="EstimatesData" QueryName="GetUserEstimates" >
<riacontrols:DomainDataSource.DataContext>
<ds:MyDomainContext />
</riacontrols:DomainDataSource.DataContext>
</riacontrols:DomainDataSource>
<datagrid:DataGrid x:Name="EstimatesGrid" ItemsSource="{Binding ElementName=EstimatesData, Path=Data}" />
MyDomainContext 有一个模型 UserEstimates 和方法 GetUserEstimatesQuery。
当页面加载时,GetUserEstimatesQuery中的断点没有被命中,该方法没有被调用。没有错误,我错过了什么?
如果我在页面加载后面编写代码,它就会绑定正常。
Using markup I can't get data to show in the grid:
<riacontrols:DomainDataSource x:Name="EstimatesData" QueryName="GetUserEstimates" >
<riacontrols:DomainDataSource.DataContext>
<ds:MyDomainContext />
</riacontrols:DomainDataSource.DataContext>
</riacontrols:DomainDataSource>
<datagrid:DataGrid x:Name="EstimatesGrid" ItemsSource="{Binding ElementName=EstimatesData, Path=Data}" />
MyDomainContext has a model UserEstimates with a method GetUserEstimatesQuery.
When the page loads, the breakpoint in GetUserEstimatesQuery does not get hit, the method is not called. There are no errors, what am I missing?
If I write code behind on the page load, it binds OK.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我也有同样的问题。我已经通过更改解决了这个问题
:
I had the same problem. I've solved it by changing:
to
忘记提及该模型来自 SQL 视图。我使用表格尝试了相同的方法,效果很好。问题是模型上没有为视图定义正确的键,它设置了大约 6 个字段作为键,但仍然无法给出唯一的值。
最终解决方案是向视图添加一个字段作为键,重新创建模型,设置主键字段,现在数据按预期显示。
Forgot to mention the model came from a SQL View. I tried the same approach using a table and it worked fine. The problem was that there was no proper key defined on the model for the view, it had set about 6 fields as the key which would still not give a unique value.
End solution was to add a field to the view to use as the key, re-create the model, set the primary key field, and now data is displaying as expected now.
您需要对 DomainDataSource 的使用情况进行一些调试,看看它是否正在调用负载。尝试处理 LoadingData 事件和 LoadedData 事件以查看发生了什么。
这可能有更多有用的信息:
http://jeffhandley.com/archive/2009/ 11/19/domaindatasource-error-handling-again.aspx
您还可以尝试在代码隐藏中调用esestimatesData.Load(),看看这是否有助于解决您的问题。
You need to do some debugging of your DomainDataSource usage to see if it's invoking the load at all. Try handling the LoadingData event and the LoadedData event to see what's going on.
This might have some more info that is helpful here:
http://jeffhandley.com/archive/2009/11/19/domaindatasource-error-handling-again.aspx
You can also try to call the estimatesData.Load() in your code-behind to see if that helps troubleshoot your issue.