我正在寻找一个事件(或另一种机制/解决方法),当在Pivot Viewer控件中完成交易卡渲染时,我可以使用它来了解。我正在使用SL5版本的控件,并添加到它的ItemSource中(通过一个可观察的集合)。目前,在为控件提供数据和在透视查看器控件上看到动画之间存在相当大的滞后。我的填充ItemSource的线程退出,在盯着空白屏幕5-10秒后,用户最终看到了交易卡的图像。内置事件不支持任何指示何时呈现交易卡图像处于"就绪"状态。
我遇到了同样的问题,所以我通过扩展pivotwiewer控件来编写自己的解决方案:http://stevenhollidge.blogspot.ch/2012/12/pivotviewer-itemsloaded-event.html
我希望有人发现这个有用!
我对此进行了研究(与PivotViewer开发人员交谈),目前还无法确定渲染何时完成。
对您来说,最好的选择可能是调查SL渲染性能,并在加载集合后查找下降。不漂亮,可能无论如何都不起作用。。。
起点:http://msdn.microsoft.com/en-us/library/bb980092.aspx
Jason R.ShaverPivotViewer 的上一个PM
我发现的检测视觉效果何时加载的最佳方法是找到MultiScaleImage对象,检测图像是"正在下载"还是"空闲",以及图像的视口是什么:
以下是如何在SL5:中的数据透视查看器上获取该对象
对PivotViewer对象进行子类化,并将以下内容放在OnApplyTemplate()重写中:
PartContainer = (Grid)this.GetTemplateChild("PART_Container");
cvv = (PartContainer).Children[2] as CollectionViewerView;
if (cvv != null)
{
cvvm = ViewBehaviors.GetViewModel(cvv);
Grid container = cvv.Content as Grid;
Border viewerBorder = container.Children[1] as Border;
Grid cvGrid = viewerBorder.Child as Grid;
cvc = cvGrid.Children[0] as CollectionViewContainer;
}
然后您就有了对cvv的引用-CollectionViewerView。
在数据透视查看器对象上设置ItemsSource时,启动一个计时器,每隔300毫秒左右检查一次:
ItemViewerView ivv = ((Grid)(((UserControl)(cvc.Content)).Content)).Children[0] as ItemViewerView;
Grid g = (((Grid)ivv.Content).Children[0] as Grid);
ContentControl cc1 = (g.Children[0] as ContentControl);
if (cc1 != null)
{
Canvas cvs = cc1.Content as Canvas;
if (cvs != null && cvs.Children.Count > 0)
{
var contentControl = cvs.Children[0] as ContentControl;
if (contentControl != null)
{
MultiScaleImage x = contentControl.Content as MultiScaleImage;
bool isIdle = x.Source != null && !x.IsDownloading && x.IsIdle;
// This could be more precise, but the origin is by default set to 99999 when a new image is loaded in - we're watching for when this value changes.
bool inViewPort = x.SubImages[x.SubImages.Count - 1].ViewportOrigin.X < 999999;
// if both of these boolean values are true, then the images will be displaying on the screen.
}
}
}
请注意,这是版本为5.0.61118的SL.dll(此代码在未来的版本中很可能会中断)