2nd time binding to PointCollection not being rendered

狂风中的少年 提交于 2019-12-11 07:04:24

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/6674395/2nd-time-binding-to-pointcollection-not-being-rendered

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!