Click here to Skip to main content
15,887,746 members
Please Sign up or sign in to vote.
4.00/5 (1 vote)
See more:
Hello,I have a WPF app and I want to know what is the problem with my binding.I have a combobox that holds some values,and when I put the breakpoint where the function for the combobox is,after I put the breakpoint and I want to debug,I won't enter the applciation,instead,when I'm about to go into the application it breaks.That's not normal since it should break when I select the value in the combobox,so it should enter the application and I should be able to see all the functionalities of the Window.What could be the problem that causes this?
This is my method for the combobox:
public IEnumerable<AvailableCours> GetByEducation()
       {

           using (var context = new AttendanceStudentsEntities())
           {
               var query = (from data in context.AvailableCourses select new { Education = data.education }).ToList().Select(c => new AvailableCours { education = c.Education }).ToList();

               return query.ToList();

           }

       }


This is the binding in the view:
<ComboBox HorizontalAlignment="Left" Margin="166,229,0,0" Grid.Row="2" DisplayMemberPath="education" VerticalAlignment="Top" Name="cbxCourses" ItemsSource="{Binding Education}" SelectedItem="{Binding Path=Education}" IsSynchronizedWithCurrentItem="True" Width="264" Grid.RowSpan="2"/>


If something else would be relevant to understand the problem,please tell me and I'll post it.I also get binding errors such as:

System.Windows.Data Information: 41 : BindingExpression path error: 'education' property not found for 'object' because data item is null.  This could happen because the data provider has not produced any data yet. BindingExpression:Path=education; DataItem=null; target element is 'ComboBox' (Name='cbxCourses'); target property is 'NoTarget' (type 'Object')

System.Windows.Data Information: 20 : BindingExpression cannot retrieve value due to missing information. BindingExpression:Path=education; DataItem=null; target element is 'ComboBox' (Name='cbxCourses'); target property is 'NoTarget' (type 'Object')

System.Windows.Data Information: 21 : BindingExpression cannot retrieve value from null data item. This could happen when binding is detached or when binding to a Nullable type that has no value. BindingExpression:Path=education; DataItem=null; target element is 'ComboBox' (Name='cbxCourses'); target property is 'NoTarget' (type 'Object')

System.Windows.Data Information: 10 : Cannot retrieve value using the binding and no valid fallback value exists; using default instead. BindingExpression:Path=education; DataItem=null; target element is 'ComboBox' (Name='cbxCourses'); target property is 'NoTarget' (type 'Object')


What I have tried:

I have tried to make the view again,I redone the db,I changed the method of the GetEducation() so that the Courses list would add the value of the items(courses),still didn't work.I would really appreciate an advice.
Posted
Updated 4-May-18 3:11am
v2
Comments
Afzaal Ahmad Zeeshan 4-May-18 11:24am    
Just test that since you are renaming the property in your anon type, select new { Education = data.education }), check the Education as the binding name.

1 solution

The code you are showing above returns an IEnumerable but it does not update the Education property. Maybe thats your problem?

Can you post the complete code for the view and viemodel with regard to the combobox?
You should also change your sample code such that it reads its data from an array of strings instead of a database to make sure the sample code can be verified. Then when we have figured out what is wrong with the binding you can always look at inserting the database stuff underneath ...
 
Share this answer
 

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