2013-10-04 51 views

回答

5

你可以通過Content.ActualHeight/Width屬性當前的寬度和高度 這裏的代碼片段

public void showPopUp() 
    { 
     //get heigth and width 
     double height=Application.Current.Host.Content.ActualHeight; 
     double width = Application.Current.Host.Content.ActualWidth; 


     //child content 
     StackPanel stk = new StackPanel(); 
     stk.Height = height; //set height 
     stk.Width = width; //set width 
     stk.Background = new SolidColorBrush(Colors.Red); 
     TextBlock txtblock = new TextBlock() { FontSize=40, Text="HELLO WORLD", TextWrapping=TextWrapping.Wrap}; 
     stk.Children.Add(txtblock); 


     Popup _popup = new Popup(); 

     _popup.Child = stk; //set child content 

     this.LayoutRoot.Children.Add(_popup); 
     _popup.IsOpen = true; 

    } 

,然後你會得到這樣的結果;) enter image description here

+0

謝謝你的帖子,這是美好的。自從......以來已經有一段時間了: – SevenWow

1

對於Windows Phone的8.1你可以通過Window獲得當前應用的寬度和高度。當前.Bounds

double height = Window.Current.Bounds.Height; 
double width = Window.Current.Bounds.Width;