WPF DataBinding Error: Cannot find source for binding with reference 'RelativeSource FindAncestor'

大憨熊 提交于 2019-12-01 16:17:14

This is a known bug; check http://wpf.codeplex.com/discussions/47047 and http://social.msdn.microsoft.com/Forums/en-GB/wpf/thread/af7cd462-febe-482b-9a04-61b076933c7b for more details.

In the first URL (Codeplex) I am going to post a workaround; however, it involves modification of the WPF Toolkit source code.

First off, the WPF datagrid's rows are white by default so why are you setting them white in your style? You could get rid of the DataGrid.Resources bit completely and replace AlternationCount=2 with AlternatingRowBackground="FFCAC6C6" (although this will cause the first row to be white and the second one to be colored etc. If that's not acceptable you can still delete the trigger which sets the background white).

About the errors - since the code your provided does not contain any bindings with RelativeSource set, I can only conclude two things:

1) Either you didn't provide the full code and you need to relook your bindings which have RelativeSource in them, since clearly there is an error somewhere.

2) You aren't using the WPF's builtin DataGrid. Perhaps the WPF toolkit DataGrid from codeplex? Although I belive that it shouldn't have those errors either, it's more likely conclusion 1 again.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!