2013-04-30 73 views
0

在WindowsVista 7.1中,我一次加載了所有數據透視項內容的數據透視控件。我正在開發跨平臺應用程序。等待事件完成

Issue: 在我的應用程序中,每個數據透視項都具有WebBrowser控件。加載時間爲java script calls are conflicted的所有數據透視表項內容。

要求: 如果具有4個樞軸物品等ITEM1,ITEM2,項目3和ITEM4,然後load item2 after the content of item1 load finished樞轉控制。

編輯1:我曾嘗試下面的代碼http://www.c-sharpcorner.com/UploadFile/1d42da/synchronization-events-and-wait-handles-in-C-Sharp/

ManualResetEvent mre = new ManualResetEvent(false); 
foreach (PivotDetails pivotdetails in pivtdetailslist) 
{     
    PivotItem pivotitem = new PivotItem(); 
    pivotitem.Header = pivotdetails.header; 
    WebBrowserControl browsercontrol = new WebBrowserControl(this); 
    browsercontrol.Navigate(pivotdetails.url); 
    pivotitem.Content = browsercontrol; 
    mre.Reset(); 
    myPivot.Items.Add(pivotitem); 
    mre.WaitOne(); 
} 

private void webBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) 
{ 
    mre.Set(); 
} 

EDIT1問題:等待屏幕顯示只沒能看到設計頁面。

回答

0

我用下面的代碼爲「等待完成事件」

foreach (PivotDetails pivotdetails in pivtdetailslist) 
{     
    PivotItem pivotitem = new PivotItem(); 
    pivotitem.Header = pivotdetails.header; 
    WebBrowserControl browsercontrol = new WebBrowserControl(this);  
    pivotitem.Content = browsercontrol; 
    mre.Reset(); 
    myPivot.Items.Add(pivotitem); 
    mre.WaitOne(); 
} 

private void webBrowser_LoadCompleted(object sender, System.Windows.Navigation.NavigationEventArgs e) 
{ 
    myPivot.isHitTestVisible = true; 
} 

private void myPivot_SelectionChanged(object sender, SelectionChangedEventArgs e) 
{ 
      Pivot pivot = sender as Pivot; 
      PivotItem currentPivot= pivot.SelectedItem as PivotItem; 
      if (currentPivot.Content is WebBrowserControl) 
      { 
       WebBrowserControl bc = currentPivot.Content as WebBrowserControl; 
       if (bc.getWebView().Source == null) 
       {      
        bc.Navigate(pivtdetailslist[pivot.SelectedIndex].url); 
        bc.getWebView().LoadCompleted += new System.Windows.Navigation.LoadCompletedEventHandler(webBrowser_LoadCompleted); 
        myPivot.IsHitTestVisible = false; 
       } 
      } 
}