Skip to main content
 首页 » 编程设计

c#之如何在 Windows Phone 中居中弹出用户控件

2024年02月13日16EasonJim

我想在屏幕中间居中弹出用户控件,我该怎么做?

 Popup p = new Popup(); 
 p.Child = new loadingtest(); 
 
  p.isOpen = true; 

请您参考如下方法:

var p = new Popup(); 
var content = new TextBox { Text = "hello world!" }; 
p.Child = content; 
p.VerticalOffset = (this.ActualHeight - content.ActualHeight) / 2; 
p.HorizontalOffset = (this.ActualWidth - content.ActualWidth) / 2; 
p.IsOpen = true; 

this 是 PhoneApplicationPage,popup 是 LayoutRoot Grid 的子项。