2014-07-18 35 views
2

我試圖彈出一個PopUp控件,其中包含一些按鈕,但不幸的是,當我運行我的應用程序時,它出現在左上角。我的意思是在(0,0)[in explain(x,y)axis]。如何在Silverlight中彈出PopUp控件

我的代碼,這樣做是:

<Popup x:Name="myPopup" Margin="-34,0,-31,0" Grid.Row="2" Grid.Column="1" Height="78" VerticalAlignment="center" HorizontalAlignment="center"> 
    <Border Background="Silver" BorderThickness="2" BorderBrush="Black" Height="224" Width="371"> 
     // Here is a grid which contains all my buttons and otherthing on popup 
    </Border> 
</Popup> 

能有人幫我在中心坡平它呢?(即使我做了HorizontalAlignment="center"VerticalAlignment="center"也沒有做)。

+1

當我看到這個問題出現在我的飼料中彈出一個彈出彈出彈出我幾乎扔我的彈出。相反,我打電話給我的彈出窗口讓他知道。 – DavidG

回答

1

你可以使用ChildWindow,這將自動出現在屏幕中央

,或者如果你想手動放在中心的彈出窗口中,您可以手動調整HorizontalOffsetVerticalOffset

double positioningX = (Application.Current.Host.Content.ActualWidth/2) - (widthOfDialog/2); 
double positioningY = (Application.Current.Host.Content.ActualHeight/2) - (heightOfDialog/2); 
if (positioningX > 0) 
    popup.HorizontalOffset = positioningX; 
if (positioningY > 0) 
    popup.VerticalOffset = positioningY; 
+0

@Sajetharan當我使用childwindow彈出中心,但使彈出區域不太明顯。所以我必須避免這種情況。這就是爲什麼我使用PopUp控件。 – user3735822

+0

@ user3735822你試過上面那個 – Sajeetharan

+0

我用ChildWindow嘗試過,但它很好地彈出,但它使得該區域的其餘部分在彈出窗口上不太明顯。你知道任何方法使孩子周圍的區域POP UP可見嗎? (因爲PopUp控件也不被我的導師接受,因爲它不會像meassageBox那樣彈出)。或者如果你知道任何其他方法來實現這一點。 – user3735822

0

使用VerticalOffset和Horizo​​ntalOffset

+0

我想這是用於WPF – Sajeetharan

+0

我已經在我的文章中描述了這一點,請編輯speficy您的編輯 – Sajeetharan

0

在我的情況下這樣解決它:

double width = Convert.ToDouble(HtmlPage.Window.Eval("screen.width")); 
       double height = Convert.ToDouble(HtmlPage.Window.Eval("screen.height")); 

       AdvertisingControl ac = new AdvertisingControl(); // Your user control here.. 

       this.p = new Popup() 
       { 
        VerticalOffset = (height - ac.Height)/2.0, 
        HorizontalOffset = (width - ac.Width)/2.0, 
        Width = ac.Width, 
        Height = ac.Height, 
        Child = ac, 
       }; 

       this.p.IsOpen = true; 
相關問題