第二次绑定到PointCollection未被渲染 [英] 2nd time binding to PointCollection not being rendered

查看:210
本文介绍了第二次绑定到PointCollection未被渲染的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ItemsControl的ItemsSource(通过代码)将INotifyPropertyChanged对象(数据模型)的ObservableCollection(让它称为Items)。该数据模型具有PointCollection属性。



视图(XAML)绑定到PolyLine上的PointCollection(在Points属性上)。
最初当我将此Items集合设置到ItemsControl.ItemsSource时,我可以看到这些行确实呈现。



问题:
当我将ItemsControl.ItemsSource设置为其他东西(如另一个没有任何行的ObservableCollection),那么将其设置回原始集合,即使集合SHOULD呈现,我无法看到这些行他们因为收集数据模型包含PointCollection。



从我能够研究的内容中,对于绑定到PointCollection有一些特别的困难。我想知道有没有人在之前和/或知道一个方法来解决这个问题(即无效控制以某种方式强制重画)?



谢谢。

解决方案

Alvin,



我不知道如果将工作,但是您是否尝试创建一个新的PointCollection?:

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

如果这不起作用,也许可能需要使用更多基于WPF的语法: p>

  myItemsControl.SetValue(ItemsControl.PointsProperty,newCollection); 

我自己遇到了一些PointCollection问题,所以如果这些选项之一有帮助,让我知道。 / p>

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.

解决方案

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.

这篇关于第二次绑定到PointCollection未被渲染的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆