布局更新时为什么不激发LayoutUpdated事件? WP7
问题描述:
我的问题重新渲染全景项目的LayoutUpdated事件。 无论我将LayoutUpdated事件分配给哪个项目,在滚动项目时它都不会触发。这里是我的代码:布局更新时为什么不激发LayoutUpdated事件? WP7
<controls:Panorama Grid.Row="2" x:Name="WebScrollView" >
<!--Panorama item one-->
<controls:PanoramaItem Width="480" x:Name="LeftPanoramaControl"/>
<!--Panorama item two-->
<controls:PanoramaItem Width="480" x:Name="MiddlePanoramaControl"/>
<controls:PanoramaItem Width="480" x:Name="RightPanoramaControl"/>
</controls:Panorama>
在我的C#类,我说:
private void BrowsersLoaded()
{
//first, we stop the progressbar
AnimatedProgressBar.StopProgressBar();
//next, we want to make sure that the left and right browser are going to load new content, as now, for instance, the left browser is placed upon the middlecontent
//so, we cannot just say _leftBrowser.Navigate, this will screw up the view
LeftPanoramaControl.Visibility = _leftControlVisibility;
RightPanoramaControl.Visibility = _rightControlVisibility;
WebScrollView.UpdateLayout();
WebScrollView.DefaultItem = MiddlePanoramaControl;
//this seems like beating around the bush, doesm't it?
//well, A problem I encountered was that the LayoutUpdated event was called even before I could do anything, check whatever boolean, cause they were all
//set to true even before the event was fired, which called upon the CheckID method, and gave a huge infinite loop.
MiddlePanoramaControl.LayoutUpdated += new EventHandler(WebScrollView_LayoutUpdated);
}
但是当我通过全景项目滚动它不会着火。 有没有人有任何想法为什么?
格尔茨,Geekpeek
答
MSDN来自:
时发生与 当前分派器的变化相关联的各种可视元素的布局。
正如你所观察到的,LayoutUpdated
事件可以被任何UI元素进行处理,并会产生相同的结果,无论你用它来处理这个事件哪个元素。还请注意sender
参数是alawys null。
现在,为什么当您滚动全景物品时不会触发?每当Silverlight框架执行布局传递时,即触发LayoutUpdated
事件,即根据可视树和树中各个面板和元素的特性计算每个UI元素的位置。
仅仅因为您在手机屏幕上看到某物发生了移动,并不表示已发生布局通过。设置RenderTransforms
的动画不会导致布局更改。
布局昂贵,所以我期望全景控件的设计方式使得每个项目在开始滚动项目前都已确定其布局。
为什么不处理Panorama.SelectionChanged事件呢?