大家好,
我有一个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。