SL4 - 将 DataGridTextColumn 绑定到属性
我有一个数据网格。在 DataGrid 的 AutoGenerateColumn 事件中,我有一些如下所示的代码:
if (e.Property.Name.Contains("MetaData"))
{
var descCol = new DataGridTextColumn(e.Property);
var bnd = new Binding("Description");
bnd.Mode = BindingMode.TwoWay;
descCol.Binding = bnd;
e.Column = descCol;
e.Column.Header = "Description";
return;
}
该列绑定到一个 MetaData 类型,该类型有一个名为 Description 的字符串属性,我希望将其显示在我的 DataGrid 中。到目前为止,我无法获取要在 DataGrid 中显示的 Description 属性的值。我认为我传递到 Binding 构造函数的路径可能不正确。我也尝试过“MetaData.Description”,但它也不起作用。
谁能帮助我正确设置 DataGridTextColumn 上的绑定?
I have a DataGrid. In the DataGrid's AutoGeneratingColumn event I have some code that looks like this:
if (e.Property.Name.Contains("MetaData"))
{
var descCol = new DataGridTextColumn(e.Property);
var bnd = new Binding("Description");
bnd.Mode = BindingMode.TwoWay;
descCol.Binding = bnd;
e.Column = descCol;
e.Column.Header = "Description";
return;
}
The column binds to a type MetaData which has a string property named Description that I would like displayed in my DataGrid. So far I've been unable to get the value of the Description property to display in my DataGrid. I think the path I am passing into the Binding constructor might be incorrect. I've tried "MetaData.Description" as well and it doesn't work either.
Can anyone help me properly set up the binding on my DataGridTextColumn?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
将其更改
为
Change this,
to
var bnd = new Binding("MetaData.Description");
在我也解决了这个问题之后,我做了这个技巧:
实体框架/RIA服务包括不工作
var bnd = new Binding("MetaData.Description");
Did the trick after I also solved this issue:
Entity Framework / RIA Services Include not working