Click here to Skip to main content
15,887,135 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
I have a screen that shows what is in effect a master-detail view. The master is a list of projects. The detail part of the view has a ComboBox that shows the name of the Project Manager for the selected project. The ComboBox list is bound to a list of names supplied by a different class entirely.

Everything works fine until the I hit a button that is supposed to deselect everything on the screen - i.e. put the screen back into the state it was first loaded. When I set the SelectedIndex property of the ComboBox to -1, I get the following error:

System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='System.Windows.Controls.ItemsControl', AncestorLevel='1''. BindingExpression:Path=HorizontalContentAlignment; DataItem=null; target element is 'ComboBoxItem' (Name=''); target property is 'HorizontalContentAlignment' (type 'HorizontalAlignment')

Does anyone have any idea what may be going wrong? Have to admit I am in the dark how to debug this. I seem to have tried everything.

Kind wishes ~ Patrick

What I have tried:

I have tried setting the SelectedItem to null at the same time as setting SelectedIndex to -1.

I have tried not setting the SelectedIndex at all, which gives no error but leaves the box displaying the name from the last project that was selected.

I have tried adding an empty string to the list of names that the ComboBox is bound to.

And I am sure I have tried about 50 other things I can't even remember.
Posted
Comments
Richard Deeming 20-Jan-17 12:15pm    
Are you using MVVM?
Patrick Skelton 20-Jan-17 12:30pm    
The project is WPF, and I have tried to keep reasonably closely to the MVVM pattern, but I am not using any specific framework. Hope that answers your question.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900