如何根据组合框选择填充数据网格? [英] How to populate the datagrid depending on combobox selection?

查看:93
本文介绍了如何根据组合框选择填充数据网格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有enob值的组合框。

现在当我从组合框中选择任何值时,我想用匹配所选值的记录填充datagrid。



这是wpf mvvm项目。

严格没有代码



我尝试过的事情:



我尝试过使用selectitem属性进行组合框

I have combobox with enum values.
Now when I select any value from the combobox, I want to populate datagrid with records matching the selected value.

It's wpf mvvm project.
And strictly no code behind

What I have tried:

I have tried using selecteditem property for combobox

推荐答案

你的 ViewModel (VM)需要公开绑定到 ComboBox SelectedItem SelectedIndex 属性,以便VM可以通知用户选择。



然后您的VM可以运行查询并更新您的 ObservableCollection 将自动被绑定的 DataGrid 看到,DataGrid将反映新数据。
Your ViewModel (VM) needs to expose a property that is bound to the ComboBox SelectedItem or SelectedIndex property so the VM can be notified of the user selection.

Your VM can then run the query and update your ObservableCollection which will automatically be seen by the bound DataGrid and the DataGrid will reflect the new data.


这篇关于如何根据组合框选择填充数据网格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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