Window.Current.SizeChanged事件未触发 [英] Window.Current.SizeChanged event not firing

查看:204
本文介绍了Window.Current.SizeChanged事件未触发的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在三星系列7平板电脑上测试我的游戏。我有一个页面MainPage.xaml,它监听调整大小事件:

 private void OnLoaded(object sender,RoutedEventArgs e)
{
Window.Current.SizeChanged + = this.ViewStateChanged;
}

当事件触发时我尝试调整我的应用程序的大小:

 private void ViewStateChanged( object sender,WindowSizeChangedEventArgs e)
{
this.game.ViewStateChanged(ApplicationView.Value,(int)e.Size.Width,(int)e.Size.Height);
SharedGraphicsDeviceManager.Current.ApplyChanges();
}

第一行告诉我的应用程序代码根据需要进行更改。 (我有纵向,横向,填充和捕捉状态的视图。)第二行指示MonoGame调整SwapChainBackgroundPanel的大小。一切都按预期工作,除了
似乎随机调整大小事件没有触发。我已经更改了我的应用程序以呈现当前的ApplicationViewState并确认它错误地报告例如在平板电脑处于横向方向时处于移植模式。我可以让每个布局模式发生
。它似乎是完全随机的。


还有其他人遇到过这个问题并找到了解决方法吗?

解决方案

< blockquote>

我不确定你的 OnLoaded 何时被调用,但是当我在
OnNavigatedTo 中注册事件处理程序时,它似乎永远不会错过调整大小事件:

 protected override void OnNavigatedTo(NavigationEventArgs e){Window.Current.SizeChanged + = Current_SizeChanged;} 




I'm currently testing my game on a Samsung Series 7 tablet. I have a single page, MainPage.xaml, which listens for resize events:

private void OnLoaded(object sender, RoutedEventArgs e)
{
    Window.Current.SizeChanged += this.ViewStateChanged;
}

When the event fires I try to resize my application:

private void ViewStateChanged(object sender, WindowSizeChangedEventArgs e)
{
       this.game.ViewStateChanged(ApplicationView.Value, (int)e.Size.Width, (int)e.Size.Height);
       SharedGraphicsDeviceManager.Current.ApplyChanges();
}

The first line tells my application code to change as appropriate. (I have views for the Portrait, Landscape, Filled, and Snapped states.) The second line instructs MonoGame to resize the SwapChainBackgroundPanel. Everything works as expected except that seemingly at random the resize event is not firing. I've changed my application to render the current ApplicationViewState and confirmed that it mistaken reports being e.g. in portait mode when the tablet is in landscape orientation. I can get this to happen for each of the layout modes. It appears to be totally at random.

Has anyone else encountered this problem and found a work around?

解决方案

I'm not sure when your OnLoaded is called, but when I register the event handler in the OnNavigatedTo, it never seems to miss a resize event:

protected override void OnNavigatedTo(NavigationEventArgs e){    Window.Current.SizeChanged += Current_SizeChanged;}



这篇关于Window.Current.SizeChanged事件未触发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆