2

我的问题是全景项目的 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 );
}

但是当我滚动浏览全景项目时它不会触发。有谁知道为什么?

问候,极客

4

1 回答 1

2

来自MSDN

当与当前 Dispatcher 关联的各种可视元素的布局发生更改时发生。

正如您所观察到的,LayoutUpdated可以在任何 UI 元素上处理该事件,并且无论您使用哪个元素来处理此事件,都会产生相同的结果。另请注意,该sender参数为 alawys null。

现在,当您滚动浏览全景项目时,为什么它不会触发?每当 Silverlight 框架执行布局传递时,该LayoutUpdated事件就会触发,即它根据可视化树以及树中各种面板和元素的特征来计算每个 UI 元素的位置。

仅仅因为您在手机屏幕上看到有东西在移动,并不意味着布局传递已经发生。设置的动画RenderTransforms不会导致布局更改。

布局很昂贵,所以我希望全景控件的设计方式是在开始滚动项目之前确定每个项目的布局。

为什么不处理Panorama.SelectionChanged事件呢?

于 2012-04-11T12:18:57.260 回答