【问题标题】:PopUp in Windows Phone 7Windows Phone 7 中的弹出窗口
【发布时间】:2012-12-15 16:55:05
【问题描述】:

我想在 windows phone (C#) 中使用 popUp 元素在屏幕上查看消息

我做了以下事情:

popUpBanner = new Popup();
popUpBanner.HorizontalAlignment = HorizontalAlignment.Center;
popUpBanner.VerticalAlignment = VerticalAlignment.Center;

但是弹出元素出现在屏幕的左上角..而不是在中心

我该如何解决这个问题

【问题讨论】:

    标签: windows-phone-7 popup


    【解决方案1】:

    在 Windows Phone 中,弹出窗口不是 UserControl 类。您不想将弹出窗口居中,而是要将弹出窗口的子元素中的 ui 元素居中...

    【讨论】:

      【解决方案2】:

      更具体地说,我更新了我的代码,希望对您有所帮助。 首先让我们获取屏幕尺寸(即宽度和高度)

      var width = System.Windows.Application.Current.Host.Content.ActualWidth;
      var height = System.Windows.Application.Current.Host.Content.ActualHeight;
      

      让我们创建一个 StackPanel,为其添加背景颜色并根据设备屏幕分辨率重新调整 StackPanel 的大小。

      StackPanel stackPanel = new StackPanel();
      stackPanel.Background = new SolidColorBrush(Colors.Gray);
      stackPanel.Height = height / 4;
      stackPanel.Width = width / 2;
      

      最后创建一个 Popup 并将其作为子项添加到 StackPanel。

      Popup Popup1 = new Popup();
      stackPanel.Children.Add(Popup1);
      ContentPanel.Children.Add(stackPanel);
      Popup1.IsOpen = true;
      

      你已经完成了。根据您的需要修改您的 StackPanel 大小,因为您在这里获得了屏幕分辨率。

      【讨论】:

      • 问题是关于居中,而不是设置偏移量,这不足以处理所有屏幕分辨率
      • 我刚刚更新了我的代码。设置偏移量会带来弹出中心,这就是用户想要的。
      • 可以使用偏移量设置到中心,但也许你应该帮助他获得总宽度的方法?
      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多