WPF 组合框绑定不起作用。它没有显示确切的值
我将向您展示确切的代码和代码的输出...
这是我的 linq .dbml 文件
这是组合框 cbx_contact 代码:
<ComboBox Height="22.669" Margin="107.769,43.75,424.266,0" Name="cbx_contact" VerticalAlignment="Top" IsTabStop="True" SelectedValuePath="ContactID" IsSynchronizedWithCurrentItem="True" IsEditable="True" IsTextSearchEnabled="True">
<ComboBox.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Path=ContactName}"/>
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
这是 .cs 文件:
public Contacts()
{
InitializeComponent();
DataClasses1DataContext db = new DataClasses1DataContext();
cbx_contact.ItemsSource = db.Contacts;
cbx_contact.SelectedIndex = 0;
}
这是组合框的输出视图:
在组合框的下拉列表中,我获得了所有值,但是当我选择任何值时值文本不会改变它给出 Contact_Manager.Contact...
我不知道我在这里缺少什么... 我之前已经像这样绑定了组合框,当时它也可以工作,但这里它正在创建问题...... 预先感谢您的帮助...
I will show you the exact code and output of the code...
This is my linq .dbml file
This i the combobox cbx_contact code :
<ComboBox Height="22.669" Margin="107.769,43.75,424.266,0" Name="cbx_contact" VerticalAlignment="Top" IsTabStop="True" SelectedValuePath="ContactID" IsSynchronizedWithCurrentItem="True" IsEditable="True" IsTextSearchEnabled="True">
<ComboBox.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding Path=ContactName}"/>
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
This is the .cs file :
public Contacts()
{
InitializeComponent();
DataClasses1DataContext db = new DataClasses1DataContext();
cbx_contact.ItemsSource = db.Contacts;
cbx_contact.SelectedIndex = 0;
}
This is the output view of the combobox :
Here in the drop down list of combobox i get all the values but when i select any value the text does not change it gives Contact_Manager.Contact....
I dont know what i am missing here...
I have binded combobox like this before also it was working at that time but here it is creating probs...
thanks in advance for the help...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
应用
Applying the concepts from this answer: