本文介绍了WPF-以编程方式绑定到DataGridCheckBoxColumn的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图以编程方式将IList绑定到数据网格,并且其中一列是布尔值,所以我决定使用DataGridCheckBoxColumn而不是我通常的DataGridTextColumn.不幸的是,这似乎不起作用.

I'm trying to programmatically bind an IList to a datagrid and one of the columns is a boolean value, so I decided to use a DataGridCheckBoxColumn instead of my usual DataGridTextColumn. Unfortunately, this doesn't seem to be working.

这是我当前正在使用的代码:

This the code I am currently using:

DataGridCheckBoxColumn dgcbc = new DataGridCheckBoxColumn();
Binding b = new Binding("Convicted");

dgcbc.Header = "Convicted";
dgcbc.Binding = b;
this.dgResults.Columns.Add(dgcbc);

在为DataGrid设置源之后,将显示复选框列,但未选中它们.如果我将DGCBC切换回DGTC,则绑定正确显示为"true"或"false".有什么想法吗?

After I set the source for the DataGrid the checkbox column shows up, but they are all unchecked. If I switch the DGCBC back to a DGTC the binding correctly shows up as either "true" or "false". Any ideas?

推荐答案

您的绑定是否需要设置为Mode = TwoWay?

Does your binding need to be Mode=TwoWay?

这篇关于WPF-以编程方式绑定到DataGridCheckBoxColumn的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-29 17:52