System.Windows.Data错误:1 System.Windows.Data错误:5 (注:这是一个提问标题,不需要回答)

4

大家好,

我有一个WPF应用程序,其中包含一个DataGrid控件,其绑定的ItemsSource=MyContext.Entity1.Local(这是一个ObservableCollection)。 在这个应用程序中,有一个DataGridComboBoxColumn,如下所示:

<DataGridComboBoxColumn Header="User"
                        SelectedValueBinding="{Binding Path=USR_ID, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
                        SelectedItemBinding="{Binding Path=TBL_USR, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}"
                        ItemsSource="{Binding Path=MyEntity.TBL_USR, UpdateSourceTrigger=PropertyChanged, 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。


不要一次性回答,好吗? - William
我宁愿得到一个答案,而不是一枚滚草徽章:( 我虽然勉强通过了,但并没有真正解决我的问题。我只希望它在未来不会崩溃。 - William
我在想是不是因为我没有使用局部变量? - William
1
我遇到了完全相同的问题。所有的绑定似乎都正常工作,因为数据似乎能够正确地传递到我的属性中,但是这些错误让我觉得我做错了什么。 - Matt Zappitello
1个回答

3

谢谢提供信息。很遗憾我已经完成了那个项目,但下次我会记住这个的 :-) - William

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接