如何在windows手机中居中弹出用户控件?

时间:2013-10-03 12:14:13

标签: c# windows-phone

我想在屏幕中间放置一个弹出式用户控件,我该怎么做?

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

  p.isOpen = true;

1 个答案:

答案 0 :(得分:4)

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,弹出窗口是LayoutRoot网格的子代。