2013-03-27 3 views
1

첫째팝업이 표시되지 않는 이유는 무엇입니까?

public MainPage() 
{ 
    InitializeComponent(); 

    this.Loaded += new RoutedEventHandler(MainPage_Loaded); 
} 

void MainPage_Loaded(object sender, RoutedEventArgs e) 
{ 
    Verdienen v = new Verdienen(4, 3); 
} 

다음 : 공개 Verdienen (INT attesaInSecondiIniziale = 20, INT attesaInSecondiFinale = 8) { this.AttesaInSecondiIniziale = attesaInSecondiIniziale; this.AttesaInSecondiIniziale = attesaInSecondiFinale; MostraPerQuestaSezione = false;

 popup = new Popup(); 
     Border border = new Border(); 
     border.Background = new SolidColorBrush(Colors.LightGray); 
     border.Margin = new Thickness(3); 
     StackPanel panelVerticale = new StackPanel(); 
     panelVerticale.Orientation = Orientation.Vertical; 
     AdControl control = new AdControl(); 
     panelVerticale.Children.Add(control); 
     StackPanel panelOrizzontale = new StackPanel(); 
     panelOrizzontale.Orientation = Orientation.Horizontal; 
     Button bAltreApp = new Button(); 
     bAltreApp.Content = ""; 
     bAltreApp.Tap += new EventHandler<GestureEventArgs>(bAltreApp_Tap); 
     Button bVota = new Button(); 
     bVota.Tap += new EventHandler<GestureEventArgs>(bVota_Tap); 
     bVota.Content = ""; 
     panelOrizzontale.Children.Add(bAltreApp); 
     panelOrizzontale.Children.Add(bVota); 
     panelVerticale.Children.Add(panelOrizzontale); 
     border.Child = panelVerticale; 
     popup.Child = border; 

     this.ShowPopup(); 
    } 

    private async **System.Threading.Tasks.TaskEx** ShowPopup() 
    { 
     do 
     { 
      Debug.WriteLine("thread iniziato. pausa cominciata"); 
      await System.Threading.Tasks.TaskEx.Delay(1000 * this.AttesaInSecondiIniziale); 
      Debug.WriteLine("thread: fine pausa"); 
      popup.IsOpen = true; 
      await System.Threading.Tasks.TaskEx.Delay(1000 * this.AttesaInSecondiFinale); 
      popup.IsOpen = false; 
     } while (MostraPerQuestaSezione); 
    } 

이 코드에 팝업이 표시되지 않는 이유는 무엇입니까? 참고 : 일부 필수 코드가 없습니다! 편집 : System.Threading.Tasks.TaskEx이 오류 ("비동기 메서드의 반환 상태는 void, 작업 또는 작업이어야 함")로 표시되어 있습니다.

+0

경우 ShowPopup의 코드 ? – zzfima

+0

코드를 업그레이드했습니다. 제발, 또 한번 보자! – Spode

답변

0

Thread.Sleep을 사용하면 UI 메시지 펌프가 차단됩니다. 이렇게하면 메시지를 올바르게 처리 할 때까지 표시되지 않으므로 시스템이 팝업을 표시 할 수 없습니다.

더 나은 방법은 비동기 방식으로이 이동하고 건설 후 전화를하는 것입니다 :

public async Task ShowPopup(int attesaInSecondiIniziale = 20, int attesaInSecondiFinale = 8) 
{ 
    // Your code... 

    do 
    { 
     await Task.Delay(1000 * this.AttesaInSecondiIniziale); 
     this.ShowPopup(); 
     await Task.Delay(1000 * this.AttesaInSecondiIniziale); 
     this.HidePopup();  
    } 
    while (MostraPerQuestaSezione); 
} 

비동기 방식으로 awaitTask.Delay를 사용하면 UI를 차단하지 않습니다. 그러나 이는 WP7.5를 async targeting pack으로 타겟팅해야합니다.

+0

ok ...하지만 System.Threading.Tasks를 어떻게 추가합니까? System.Threading 만 추가 할 수 있습니다 ... "PM> Install-Package System.Threading.Tasks -Pre"를 사용했지만 프로젝트에 추가되지 않았습니다 ... – Spode

+0

ok! SDK를 리로디드했습니다! – Spode

+0

실례 합니다만, Task.Delay (int)는 WP8로만 시작합니다. – Spode

0
this.ShowPopup(); ... 
this.HidePopup(); 

당신은 this이 상황에서 호출하는

popup.ShowPopup(); ... 
popup.HidePopup(); 

해야한다, thisVerienen 객체이고 당신은 더

ShowPopup() 또는 HidePopup() 방법이 없다

+0

아니요 ... 팝업 변수를 전역 변수로 선언했기 때문에 솔루션이 될 수 있다고 생각하지 않습니다. 감사! =) – Spode

+0

다음은'this'입니까? 만약 Verdienen()의 객체를 참조하지 않는다면 C#과 OOP에 대한 나의 이해가 떨어진다. 정교한! – sircapsalot

+0

예, 이것은 Verdienen의 인스턴스를 나타냅니다. 하지만이 클래스에서 팝업 개체를 전역 개체로 선언했습니다.) – Spode

관련 문제