2014-07-18 40 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; 
相关问题