Skip to main content
Home Forums Silverlight Programming Report a Silverlight Bug Can only bind ItemsSource to IEnumerable in XAML
2 replies. Latest Post by atm_grifter on July 25, 2008.
(0)
atm_grifter
Member
8 points
28 Posts
07-23-2008 4:38 PM |
Since no one has responded to the following thread in the Controls forum, http://silverlight.net/forums/t/20873.aspx, I figured I'd go ahead and report this behavior as a bug.
To summarize in Silverlight you are not able to bind the ItemsSource of an ItemsControl to a collection that is any type other than IEnumerable, including types that implement IEnumerable. So, you can't bind to List<T> or ObservableCollection<T>. This seems like a glaring omission.
Yi-Lun L...
All-Star
25052 points
2,747 Posts
07-25-2008 1:51 AM |
Hello, thanks for reporting this issue. It looks similar to a known problem. TemplateBinding doesn't work for collection types. Note this only affects TemplateBinding. In a normal binding it should work fine. The data source can be any kind of collections. So a workaround is:
<ItemsControl x:Name="ic" Background="Blue" Margin="0,0,0,0"/>
public override void OnApplyTemplate(){base.OnApplyTemplate();ItemsControl ic = this.GetTemplateChild("ic") as ItemsControl;if (ic != null){Binding b = new Binding("TestCollection");b.Source = this;ic.SetBinding(ItemsControl.ItemsSourceProperty, b);}}
07-25-2008 10:09 AM |
Yes, this is the workaround I've decided to use. Thanks for the response!