我试图弹出一个包含一些按钮的PopUp控件,但是不幸的是,当我运行我的应用程序时,它会弹出在左上角。我的意思是在(0,0)[解释(x,y)轴]。
我这样做的代码是:
<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"
)。
您可以使用ChildWindow
,它将自动显示在屏幕中央
或者如果您要手动将弹出窗口置于中间,则可以手动调整HorizontalOffset
和VerticalOffset
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;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句