简体   繁体   English

如何将WCF RIA Services查询实体绑定到WPF标签?

[英]How to bind WCF RIA Services query entity to the WPF label?

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. 我真的很想知道为什么在第一种情况下我可以将数据绑定到DataGrid,而在第二种情况下它根本无法工作。 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: 和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 . 在两种情况下,当我调试时,都看不到l.Entitiesl.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... 但是当页面出现在DataGrid下时,我可以看到数据,但同时我得到上面的错误...

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();
        }

我假设您的实体集合为空。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM