William
William

Reputation: 591

System.Windows.Data Error: 1 System.Windows.Data Error: 5

All,

I have a WPF app that has a DataGrid control bound to ItemsSource=MyContext.Entity1.Local (which is an ObservableCollection). Inside of this app is a DataGridComboBoxColumn as follows:

<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" />

My problem is that I get the following error:

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')

I figure it has something to do with DynamicProxies, but I can't figure out what's causing this (.Local?), and how to code around this (at least, not without using a TypeConverter and Reflection, yuck).

It's either that, or something to do with WPF misbehaving (but I can't find anywhere in the above markup where I'm trying to set my entity as a string).

So I ask, does anyone know how I can force Entity1.Local[n].TBL_USR to just be a TBL_USR, or if perhaps there's another way (without reflection) I could set my SelectedItemBinding?

Thanks.

I'm using EF 4.4 (Database First) and .Net 4.0.

Upvotes: 4

Views: 2989

Answers (1)

Thomas S. Trias
Thomas S. Trias

Reputation: 1294

It turns out to be due to the Mode=TwoWay and certain invisible bindings behind the scenes (for things like the clipboard). I had tried using a string converter, but that had the odd effect of removing the display of the value when the column lost focus. The answer to THAT issue is here:

Why is my DataGridComboBoxColumn clearing its value when I navigate away from it?

It turned out to be the answer to this issue as well.

Upvotes: 3

Related Questions