Search code examples
silverlightdata-bindingsilverlight-4.0itemscontrol

2nd time binding to PointCollection not being rendered


I have an ItemsControl whose ItemsSource I assign (via code) an ObservableCollection (lets call it Items) of INotifyPropertyChanged objects (data model). This data model has a PointCollection property.

The view (XAML) binds to this PointCollection on a PolyLine (on the Points attribute). Initially when i set this Items collection to the ItemsControl.ItemsSource, i can see that the lines are indeed rendered.

Issue: When I set the ItemsControl.ItemsSource to something else (like another ObservableCollection which doesn't have any lines) THEN set it back to the original collection, I am unable to see the lines, even though the collection SHOULD render them because the collection data model's contain the PointCollection.

From what I was able to research, there is something particularly tricky about binding to a PointCollection. I was wondering if anybody has tackled this before and/or know of a way to get this to render (i.e. invalidate the control to somehow force a redraw)???

Thanks.


Solution

  • Alvin,

    I have no idea if this will work but, have you tried creating a new PointCollection?:

    PointCollection newCollection = new PointCollection( oldCollection );
    myItemsControl.ItemsSource = newCollection;
    

    If that doesn't work, maybe it may be necessary use a more WPF based syntax:

    myItemsControl.SetValue( ItemsControl.PointsProperty, newCollection );
    

    I am struggling with some PointCollection issues myself so if either of these options help, let me know.