简体   繁体   English

从数据网格中提取数据并在WPF中的组合框内的复选框上显示它们

[英]Pull data from a datagrid and display them on checkboxes within a combobox in WPF

Please am new to WPF and am creating an application in which a user can select multiple items via checkboxes within a combobox. 请WPF的新手,并正在创建一个应用程序,用户可以在其中通过组合框内的复选框选择多个项目。 The items on the checkboxes are subject to change so, i want to add an editable datagrid table. 复选框上的项目可能会更改,因此,我想添加一个可编辑的datagrid表。 Please, my problem now is to make any changes on the datagrid be reflected by the checkboxes. 拜托,我现在的问题是要使数据网格上的任何更改都通过复选框反映出来。 I was only to add the checkboxes within the combox with xaml and have finished with the styling but don't know how to go about the codes. 我只是用xaml在combox内添加复选框,并完成了样式设置,但是不知道如何处理代码。

Seems to me like what you need is to bind the list of items from the DataGrid to the ComboBox (let them have binding to the same DataContext ), and set the ComboBox 's ItemContainerStyle to display a CheckBox . 在我看来,您需要的是将DataGrid中的项目列表绑定到ComboBox (让它们具有绑定到相同的DataContext ),然后将ComboBoxItemContainerStyle为显示CheckBox

I don't fully understand what the check of the CheckBox should display, but perhaps it can be data bound to some other property or to the data item itself and use a converter, or it can look at a property of the data item and use Triggers or DataTriggers. 我不完全了解CheckBox的检查应显示什么,但是也许它可以是绑定到其他属性的数据,也可以是数据项本身并使用转换器,或者它可以查看数据项的属性并使用触发器或DataTriggers。

Perhaps if you posted some code we could give a better answer... 也许如果您发布了一些代码,我们可以给出更好的答案...

Hope it helps. 希望能帮助到你。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM