代码之家  ›  专栏  ›  技术社区  ›  Igor Zevaka

如何在WindowsPhone7系列上获得屏幕大小?

  •  18
  • Igor Zevaka  · 技术社区  · 14 年前
    5 回复  |  直到 12 年前
        1
  •  14
  •   Andréas Saudemont    14 年前

    看起来application.current.rootvisual.rendersize会给您提供这些信息。

        2
  •  66
  •   Luke Puplett    14 年前

    我用这个:

    this.ScreenWidth = System.Windows.Application.Current.Host.Content.ActualWidth;
    this.ScreenHeight = System.Windows.Application.Current.Host.Content.ActualHeight;
    

    有很多方法可以屏蔽应用程序。如果是针对xaml的,则可以绑定到layoutroot的属性。

    Height="{Binding ElementName=LayoutRoot,Path=ActualHeight}"
    
        3
  •  8
  •   quetzalcoatl    13 年前

    我还不能投赞成票 (实际上,现在我可以了,我做到了) ,但我想指出的是“luke puplett”的答案,包括application.current.host.content是正确的,而不是“andr_”(saudemont)建议渲染的答案。

    我将使用在教程或msdn示例应用程序中常用的名称。

    我说host.current更合适,因为在应用程序的最开始,特别是在wp7上(我不知道它在pc上的“常规”sl3/sl4上是如何的),也就是说,在第一页的构造函数中,renderSize属性还没有正确设置为“rootvisual”的应用程序正在构造中,尚未在“app.xaml.cs”中分配。至少在这一点上,renderSize=size{0,0}

    另一方面,如果只有应用程序正确启动,主机.content将被设置为某个phoneframe,即正确的全屏大小并旋转到实际屏幕位置。我猜一开始它就是启动启动启动屏幕(jpg文件中的空的或静态的)

        4
  •  4
  •   SwissCoder    13 年前

    如果要从XNA游戏中访问显示大小,请使用以下命令:

    graphics.GraphicsDevice.DisplayMode.Width
    

    graphics.GraphicsDevice.DisplayMode.Height
    

    图形是当前游戏的图形设备管理器!

        5
  •  1
  •   Flexo - Save the data dump sunny moon    13 年前

    整个屏幕:

    (App.Current.RootVisual as FrameworkElement).ActualHeight
    (App.Current.RootVisual as FrameworkElement).ActualWidth
    

    当前页:

    如果您想知道可见大小(考虑到AppBar/SystemTray),那么只需在页面上要求它。