我的问题是重写全景项目的LayoutUpdated事件。 我将LayoutUpdated事件分配给哪个项目并不重要,当我滚动项目时它不会触发。这是我的代码:
<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 );
}
但滚动浏览全景项时,它不会触发。 有谁知道为什么?
greetz,Geekpeek
答案 0 :(得分:2)
来自MSDN:
当各种视觉元素的布局相关联时发生 当前的Dispatcher发生了变化。
正如您所观察到的,LayoutUpdated
事件可以在任何UI元素上处理,并且无论您使用哪个元素来处理此事件,都会产生相同的结果。另请注意,sender
参数是alawys null。
现在,为什么滚动浏览全景项目时不会触发?每当Silverlight框架执行布局传递时,LayoutUpdated
事件就会触发,即它会根据可视树以及树中各个面板和元素的特征计算每个UI元素的位置。
只是因为你在手机屏幕上看到了一些移动,并不意味着发生了布局传递。设置RenderTransforms
的动画不会导致布局更改。
布局很昂贵,所以我希望全景控件的设计方式是在开始滚动项目之前确定每个项目的布局。
为什么不处理Panorama.SelectionChanged事件呢?