为什么应用程序出错? [英] Why does the application breaks wrong?

查看:125
本文介绍了为什么应用程序出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,我有一个WPF应用程序,我想知道我的绑定有什么问题。我有一个组合框保存一些值,当我把断点放在组合框的功能所在的时候,我放了断点,我想调试,我不会进入applciation,相反,当我即将进入应用程序时它会中断。这是不正常的,因为它应该在我选择组合框中的值时中断,所以它应该输入应用程序和我应该能够看到Window的所有功能。可能是导致这个问题的问题?

这是我对组合框的方法:

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





我尝试过:



我试图再次查看视图,我重做了数据库,我更改了GetEducation()的方法,以便课程列表添加项目的值(课程)我仍然没有工作。我真的很感激建议。



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.

推荐答案

上面显示的代码返回一个IEnumerable,但它没有更新Education属性。也许那就是你的问题?



你能发布关于组合框的视图和viemodel的完整代码吗?

你也应该改变您的示例代码,以便它从字符串数组而不是数据库中读取数据,以确保可以验证示例代码。然后,当我们弄清楚绑定有什么问题时,你总是可以看看插入数据库的东西......
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 ...


这篇关于为什么应用程序出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆