有人知道为什么.NET 4.0中的数据绑定工作方式不同吗? 即在.NET 4.0中,RelatedPropertyManager.GetItemProperties()返回父对象类型的属性,而不是相关对象类型的属性,如以下示例代码:
using System;
using System.Windows.Forms;
static class Program
{
static void Main()
{
using (Form form = new Form())
{
ParentObject parent = new ParentObject();
BindingManagerBase bindingManager =
form.BindingContext[parent, "Nested"];
Console.WriteLine("Has Code1 property: " +
(bindingManager.GetItemProperties()["Code1"] != null));
Console.WriteLine("Has Code2 property: " +
(bindingManager.GetItemProperties()["Code2"] != null));
// .NET 2.0:
// Has Code1 property: False
// Has Code2 property: True
// .NET 4.0:
// Has Code1 property: True
// Has Code2 property: False
Console.ReadKey();
}
}
class ParentObject
{
public NestedObject Nested { get; set; }
public string Code1 { get; set; }
}
class NestedObject
{
public string Code2 { get; set; }
}
}
我也在微软社区上提出了问题,但目前还没有得到答复。