2014-11-02 297 views
1

在點擊事件中,我想在後面的代碼中顯示一個彈出窗口,但彈出窗口不顯示?彈出窗口不顯示

void PopupDisplay_Tap(object sender, System.Windows.Input.GestureEventArgs e) 
    { 
     if (sender != null) 
     { 
      p = new Popup 
      { 
       Width = 480, 
       Height = 580, 
       HorizontalAlignment = System.Windows.HorizontalAlignment.Center, 
       VerticalAlignment = System.Windows.VerticalAlignment.Center      
      }; 

      Border b = new Border(); 
      b.BorderBrush = new SolidColorBrush(Colors.Gray); 
      b.BorderThickness = new Thickness(2); 
      b.Margin = new Thickness(10, 10, 10, 10); 

      p.Child = b; 
      p.IsOpen = true; 
     } 
    } 
+0

不知也許'Popup'是走出去範圍和被處置?嘗試在此方法之外定義一次'Popup',然後在需要顯示時調用'IsOpen = true'。只是一個猜測 - 我不是一個Windows手機開發。 – 2014-11-02 15:59:55

+0

從你的代碼中我注意到了Popup沒有添加到可視化樹中。 – 2014-11-02 21:19:36

回答

1

想想你想彈出過像Pivot這是非常錯誤的頂層控制。

Popup with Pivots

如果這是一個Grid,它會彈出沒有問題。爲了解決這個問題,你必須把它添加到相同的視覺水平,像這樣的支點:

<Grid x:Name="ContentPanel" Margin="0,0,0,0"> 
    <phone:Pivot x:Name="MainDisplay"> 
    <!-- more code --> 
    </phone:Pivot>  
</Grid> 

然後在你的代碼隱藏

// I made with a thickness of 100, so we can see the border better 
Popup p; 

p = new Popup 
{ 
    Width = 480, 
    Height = 580, 
    VerticalOffset = 0 
}; 

Border b = new Border(); 
b.BorderBrush = new SolidColorBrush(Colors.Red); 
b.BorderThickness = new Thickness(100); 
b.Margin = new Thickness(10, 10, 10, 10); 
b.HorizontalAlignment = System.Windows.HorizontalAlignment.Stretch; 
b.VerticalAlignment = System.Windows.VerticalAlignment.Stretch; 

p.Child = b; 

// add it to the same level as the pivot to over ride pivot 
this.ContentPanel.Children.Add(p); 

p.IsOpen = true; 
+1

謝謝我最終做的是在我的透視控制下定義XAML中的彈出窗口,但在主網格內。然後,根據我的需要切換「IsOpen」屬性,它工作正常。我感謝你的迴應。 – Matthew 2014-11-03 04:26:25