1
为了控制一个List<CustomObject>
的序列绑定到字段对象的,我放在类,例如:在应用程序设置
public class SerializableCustomObjectList : IXmlSerializable
{
public List<CustomObject> CustomObjectList = new List<CustomObject>();
...
}
public class CustomObject {...}
,它的实例被存储在应用程序设置该列表。我没有序列化/反序列化的问题。但是,当我尝试将公共属性CustomObjectList
绑定到ListBox时,没有任何反应。
这里是我的代码:
<ListBox Name="CustomObjectListBox">
<ListBox.ItemsSource>
<Binding Source="{x:Static p:Settings.Default}"
Path="SavedCustomObjects.CustomObjectList"/>
</ListBox.ItemsSource>
...
</ListBox>
其中SavedCustomObjects
是在Properties.Settings.Default SerializableCustomObjectList的实例。
当前的行为是列表框Items.Count
保持为零(在调试器中),即使填充了SavedCustomObjects.CustomObjectList
也是如此。
谢谢,这让它工作。 – merv 2011-03-31 23:56:52
作为参考,我发现这个例子可以完整地说明提供这个答案的三个建议中的每一个:http://wblum.org/listbind/net3/index.html – merv 2011-04-01 01:17:40