有帮助吗?

解决方案

看起来像application.current.rootvisual.rendersize将为您提供该信息。

其他提示

我用这个:

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}"

我还不能拒绝/投票(实际上,现在我可以,我这样做了), ,但我想指出的是,“卢克·普莱特(Luke Puplett)的答案包括application.current.host.content是正确的,而不是“AndréasSaudemont”的“建议”建议。

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

我说host.current更加足够,因为在应用程序的一开始,尤其是在WP7上(我不知道它在PC上的“常规” SL3/SL4) - 也就是说,例如在第一页的构造函数 - 渲染属性尚未正确设置,因为该应用程序的“ rootvisual”正在构造且尚未在“ app.xaml.cs”中分配。至少在那一点点,渲染= size = size {0,0}

另一方面,如果只有应用正确启动,则主机。包含设置为某些电话框,该电话框架是正确的全屏大小,并旋转到实际的屏幕位置。我猜想一开始就是起始飞溅屏幕(jpg文件中的空或静态)

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

graphics.GraphicsDevice.DisplayMode.Width

graphics.GraphicsDevice.DisplayMode.Height

图形是当前游戏的GraphicDeviceManager!

整个屏幕:

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

当前页面:

如果您想知道可见的大小(请考虑Appbar / SystemTray),则只需在页面上要求它即可。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top