开发者

Trouble databinding in code to wpf listbox from custom IList implementation

开发者 https://www.devze.com 2022-12-27 14:57 出处:网络
I have a class CustomCollection : IList which maintains a list of CustomObject Types. This is what I tried, but it\'s not working (provider.Data is readonly):

I have a class CustomCollection : IList which maintains a list of CustomObject Types.

This is what I tried, but it's not working (provider.Data is readonly):

CustomCollection collection1 = somesampledata;

ObjectDataProvider provider = new ObjectDataProvider();
provider.ObjectType = typeof(CustomObject);
provider.Data = collection1;
// could provider.Method = "collection1.GetItems", or something similar work?

Binding binding = new Binding();
binding.Source = provider;
binding.Mode = BindingMode.OneTime;

listBox1.SetBinding(开发者_开发问答ListBox.ItemsSourceProperty, binding);


Instead of provider.Data, try provider.ObjectInstance = collection1.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号