如何将 WCF RIA 服务查询实体绑定到 WPF 标签?
我真的很想知道为什么在第一种情况下我可以将数据绑定到 DataGrid 而在第二种情况下它根本不起作用。谢谢你的任何线索!
下面是代码:
Guid id = Guid.Parse("BCBBF129-30ED-400B-9D63-403ED79FDFC7");
EntityQuery<Alert> alert = this._preDomainContext.GetAlertQuery(id);
LoadOperation<Alert> l = this._preDomainContext.Load(alert);
dataGrid1.ItemsSource = l.Entities; // <- It works fine
label1.Content = l.Entities.ElementAt(0).Message; // It gives an error
XAML:
<sdk:DataGrid AutoGenerateColumns="True" Height="100"
HorizontalAlignment="Left" Margin="173,154,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="120" />
<sdk:Label Height="28" HorizontalAlignment="Left" Margin="194,114,0,0" Name="label1" VerticalAlignment="Top" Width="120" />
错误是:
索引超出范围。必须为非负数且小于集合的大小。 参数名称:index
哦!在这两种情况下,当我调试时,我看不到 l.Entities 的任何值以及 l.Entities.ElementAt(0).Message。但是当页面出现在 DataGrid 下时,我可以看到数据,但同时我收到上面的错误...
我不确定...但是是否可以在页面出现之前看到数据?根本看不到任何数据真的很不舒服......
更新:
[RequiresAuthentication]
[EnableClientAccess()]
public class PreDomainService : LinqToEntitiesDomainService<PreEntities>
{
public Alert GetAlert(Guid id)
{
return this.ObjectContext.Alerts.Where(a=>a.ID == id).FirstOrDefault();
}
I really want to know why in the first case I can bind data to the DataGrid and in the second case it doesn't work at all. Thank you for any clue!!!
Here is the code:
Guid id = Guid.Parse("BCBBF129-30ED-400B-9D63-403ED79FDFC7");
EntityQuery<Alert> alert = this._preDomainContext.GetAlertQuery(id);
LoadOperation<Alert> l = this._preDomainContext.Load(alert);
dataGrid1.ItemsSource = l.Entities; // <- It works fine
label1.Content = l.Entities.ElementAt(0).Message; // It gives an error
And the XAML:
<sdk:DataGrid AutoGenerateColumns="True" Height="100"
HorizontalAlignment="Left" Margin="173,154,0,0" Name="dataGrid1" VerticalAlignment="Top" Width="120" />
<sdk:Label Height="28" HorizontalAlignment="Left" Margin="194,114,0,0" Name="label1" VerticalAlignment="Top" Width="120" />
And error is:
Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index
Oh! On both cases when I debug I cannot see any values for the l.Entities and as well as
l.Entities.ElementAt(0).Message. But when page appears under the DataGrid I can see the data but at the same time I get the error above...
I am not sure... But is it possible to see the data before when a page appears? It's really uncomfortable don't see any data at all...
UPDATES:
[RequiresAuthentication]
[EnableClientAccess()]
public class PreDomainService : LinqToEntitiesDomainService<PreEntities>
{
public Alert GetAlert(Guid id)
{
return this.ObjectContext.Alerts.Where(a=>a.ID == id).FirstOrDefault();
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您的实体集合是空的。
I would assume that your Entities collection is empty.