2012-11-21 50 views
3

所有,System.Windows.Data錯誤:1個System.Windows.Data錯誤:5

我有具有與之結合的ItemsSource = MyContext.Entity1.Local DataGrid控件一個WPF應用程序(它是一個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,yuck)。

這是要麼,或者與WPF行爲不檢測(但我不能找到上述標記中的任何地方,我試圖將我的實體設置爲一個字符串)。

所以我問,有誰知道我可以如何強制Entity1.Local [n] .TBL_USR只是一個TBL_USR,或者如果也許有另一種方式(沒有反射),我可以設置我SelectedItemBinding?

謝謝。

我使用EF 4.4(數據庫優先)和.Net 4.0。

+0

不是所有人都一次回答,呃? – William

+0

我寧願有一個答案然後一個風滾草徽章:(我工作通過它,但並沒有真正解決我的問題,我只是希望它不會在未來的某個時間破壞 – William

+0

我不知道是否因爲我不是't using local? – William

回答

0

原來是由於Mode = TwoWay和幕後的某些不可見綁定(如剪貼板)。我曾嘗試過使用字符串轉換器,但是當列失去焦點時,刪除了顯示值的奇怪效果。這個問題的答案的問題是在這裏:

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

原來是回答這個問題爲好。

+0

Thanks for the信息太糟糕了,我已經完成了該項目,但下次我會記住這一點:-) – William