windows-phone-7.1windows-phonepivotitem

Waiting for an Event to Complete


In Pivot control all Pivot items content is loading at a time in WindowsPhone 7.1 I am developing Cross Platform application.

Issue: In my application each Pivot Item having WebBrowser control. When loading all Pivot Item's Content at a time java script calls are conflicted.

Requirement: If Pivot Control having 4 Pivot Items like item1, item2, item3 and item4, then load item2 after the content of item1 load finished.

EDIT 1: I have tried the following code 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 Issue: Waiting screen only displaying not able to see Design page.


Solution

  • I have used the following code for "Wait to complete the event"

    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;
                    }
                }
    }