2012-04-11 71 views
2

我的問題重新渲染全景項目的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

回答

2

MSDN來自:

時發生與 當前分派器的變化相關聯的各種可視元素的佈局。

正如你所觀察到的,LayoutUpdated事件可以被任何UI元素進行處理,並會產生相同的結果,無論你用它來處理這個事件哪個元素。還請注意sender參數是alawys null。

現在,爲什麼當您滾動全景物品時不會觸發?每當Silverlight框架執行佈局傳遞時,即觸發LayoutUpdated事件,即根據可視樹和樹中各個面板和元素的特性計算每個UI元素的位置。

僅僅因爲您在手機屏幕上看到某物發生了移動,並不表示已發生佈局通過。設置RenderTransforms的動畫不會導致佈局更改。

佈局昂貴,所以我期望全景控件的設計方式使得每個項目在開始滾動項目前都已確定其佈局。

爲什麼不處理Panorama.SelectionChanged事件呢?

相關問題