c# – System.Windows.Data错误:1 System.Windows.Data错误:5
所有,
我有一个WPF应用程序,其DataGrid控件绑定到ItemsSource = MyContext.Entity1.Local(这是一个ObservableCollection). <DataGridComboBoxColumn Header="User" SelectedValueBinding="{Binding Path=USR_ID,UpdateSourceTrigger=PropertyChanged,Mode=TwoWay}" SelectedItemBinding="{Binding Path=TBL_USR,Mode=TwoWay}" ItemsSource="{Binding Path=MyEntity.TBL_USR,Source={StaticResource VM}}" SelectedValuePath="USR_ID" DisplayMemberPath="USR_WINLOGON" /> 我的问题是我收到以下错误: System.Windows.Data Error: 1 : Cannot create default converter to perform 'two-way' conversions between types MyContextType.TBL_USR' and 'System.String'. Consider using Converter property of Binding. BindingExpression:Path=TBL_USR; DataItem='Entity1Cl_4FDC0A147BE18671D96960BD8695EC4E3656B773570659474EE4FF228884E823' (HashCode=7143675); target element is 'DataGridCell' (Name=''); target property is 'CellContent' (type 'String') System.Windows.Data Error: 5 : Value produced by BindingExpression is not valid for target property.; Value='System.Data.Entity.DynamicProxies.TBL_USR30704B5EF5DAA11FBF2C9B305F529659FBCF422ED6696643EDB375A5D77F5A96' BindingExpression:Path=TBL_USR; DataItem='Entity1Cl_4FDC0A147BE18671D96960BD8695EC4E3656B773570659474EE4FF228884E823' (HashCode=7143675); target element is 'DataGridCell' (Name=''); target property is 'CellContent' (type 'String') 我认为它与DynamicProxies有关,但我无法弄清楚导致这个问题的原因(.Local?),以及如何围绕这个进行编码(至少,不是没有使用TypeConverter和Reflection,哎呀). 这或者与WPF行为异常有关(但我在上面的标记中找不到任何地方,我试图将我的实体设置为字符串). 所以我问,有没有人知道我如何强制Entity1.Local [n] .TBL_USR只是一个TBL_USR,或者如果有另一种方式(没有反射)我可以设置我的SelectedItemBinding? 谢谢. 我正在使用EF 4.4(数据库优先)和.Net 4.0. 解决方法
原来是由于Mode = TwoWay和幕后的某些不可见的绑定(对于像剪贴板这样的东西).我曾尝试使用字符串转换器,但是当列失去焦点时,这会产生奇怪的效果,即删除值的显示.这个问题的答案在这里:
Why is my DataGridComboBoxColumn clearing its value when I navigate away from it? 事实证明这也是这个问题的答案. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |