如何绑定查找组合框? [英] How do I bind a lookup combobox?
问题描述
我WPF4组合框下拉列表中错误地显示我的EF4实体的类名。下面是相关XAML:
My WPF4 combobox dropdown list is incorrectly displaying the class name of my EF4 entity. Here is the relevant XAML:
<Window.Resources>
<CollectionViewSource x:Key="myEntitiesViewSource"/>
</Window.Resources>
<ComboBox ItemsSource="{Binding Source={StaticResource myEntitiesViewSource}}" DisplayMemberPath="CategoryDescription" SelectedValuePath="CategoryID" />
下面是我Window_Loaded事件中的code:
Here is the code in my Window_Loaded event:
var categoryList = from p in _context.Categories
orderby p.CategoryNumber
select p;
System.Windows.Data.CollectionViewSource myEntitiesViewSource = ((System.Windows.Data.CollectionViewSource)(this.FindResource("myEntitiesViewSource")));
// Load data by setting the CollectionViewSource.Source property:
myEntitiesViewSource.Source = categoryList;
我的数据库有许多与一个连接表名为ProjectCategories项目和类别之间的一对多关系。类别实体被自动地作为一个单一实体来重新present两个数据库表中创建:
My database has a many to many relationship between Projects and Categories with a join table called ProjectCategories. The Categories entity was automagically created as a single entity to represent two database tables:
1)含有一个ID分类的查找表,CategoryDescription和CategoryNumber以及
1) the lookup table of Categories containing an ID, CategoryDescription and CategoryNumber and
2)连接表ProjectCategories 只包含两个字段 - 的ID从表中的项目和类别。实体模型住在从我的WPF窗口一个单独的项目。
2) the join table ProjectCategories containing only two fields - the IDs from the tables Projects and Categories. The entity model lives in a separate project from my WPF window.
我的目标是让用户选择从下拉列表中CategoryDescription,然后单击添加类别按钮将选定的类别添加到ProjectCategories的单独列表。随着当前code我看到在组合框中文本区域多次正确CategoryDescription但下拉列表中只显示实体类名称类别(按它pceded $ P $的命名空间)!
My goal is to allow the user to select a CategoryDescription from the dropdown list, then click an Add Category button to add the selected Category to a separate list of ProjectCategories. With the current code I see the correct CategoryDescription in the combobox text area but the dropdown list displays only the entity class name Categories (preceded by it's namespace) multiple times!
如何我正确地使这个简单的查找组合框的绑定,并显示CategoryDescriptions列表和类别ID的SelectedValue的注意:我会接受一个code唯一方法留下了CollectionViewSource中XAML如果可能的话。
How do I make this simple lookup combobox bind correctly and display a list of CategoryDescriptions and a SelectedValue of CategoryID? Note: I'd accept a code only approach leaving out the CollectionViewSource in XAML if it's possible.
谢谢!
推荐答案
没关系。我问这个问题,并回答了它自己。有什么错我的code或XAML。 的问题通过使用第三方主题的样式我的控制造成的。一旦我删除了主题组合框结合问题就走了。有关详细信息see这个帖子。
Nevermind. I asked this question and have answered it myself. There was nothing wrong with my code or XAML. The problem was caused by the use of a third party theme to style my controls. Once I removed the theme the combobox binding problem went away. For more details see this post.
这篇关于如何绑定查找组合框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!