将数据加载到CollectionViewSource [英] Load data to CollectionViewSource

查看:103
本文介绍了将数据加载到CollectionViewSource的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,

我尝试使用下面的代码将数据加载到CollectionViewSource.但是它将引发异常.如何解决此问题?

Hi All,

I''ve try to load data to CollectionViewSource using below code.But it will throw exception.How can I solve this problem?

_CollectionViewSource = (CollectionViewSource)this.FindResource("EmpAttendanceViewSource");
            if (dtp_Date.SelectedDate != null)
            {
                var obj = from ea in db.EmployeeAttendances
                          join emp in db.Employees
                          on ea.EmployeeId equals emp.EmployeeId
                          where ea.InDate == dtp_Date.SelectedDate
                          select new { emp.EmployeeFirstName, ea.InTime, ea.OutTime, ea.NoOfHours };
                _CollectionViewSource.Source = (CollectionViewSource)obj;



例外是,
{"TwoWay或OneWayToSource绑定不适用于类型为''<> f__AnonymousType21`4 [System.String,System.DateTime,System.Nullable`1 [System.DateTime] ,System.Nullable`1 [System.Double]]''."

请帮帮我.
谢谢,
Chamara



Exception Is,
{"A TwoWay or OneWayToSource binding cannot work on the read-only property ''InTime'' of type ''<>f__AnonymousType21`4[System.String,System.DateTime,System.Nullable`1[System.DateTime],System.Nullable`1[System.Double]]''."

Please help me.
Thanks,
Chamara

推荐答案

没有WPF UI代码很难猜测,但是您应该能够将BindingMode设置为OneWay.如果"InTime"属性设置为TextBox

It''s hard to guess without WPF UI code, but you should be able to set the BindingMode to OneWay. In case ''InTime'' property is set to TextBox

<textbox text="{Binding Path=InTime, Mode=OneWay}" />


这篇关于将数据加载到CollectionViewSource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆