Windows 8应用从App.xaml.cs访问页面的方法 [英] windows 8 App accessing page method from App.xaml.cs
问题描述
可能是一个愚蠢的问题,所以我提前道歉。我是新来构建Windows 8 Store应用。
Probably a stupid question so I apologise in advance. I am new to building a Windows 8 Store App.
我需要在我的网页脚本运行的一些方法,当应用程序被暂停。我只有一个页面,我在Page1.xaml.cs文件中的一些公共的方法。我想从App.xaml.cs文件OnSuspending()方法调用它们。我需要确保一些文本文件的保存位置。
I need to run some methods on my page script when the App gets suspended. I only have a single page and I have the some public methods in the Page1.xaml.cs file. I want to call them from the OnSuspending() method in the App.xaml.cs file. I need to make sure that some of the text files are saved.
我如何创建我的第1页剧本的参考?
How can I create a reference to my Page1 script?
推荐答案
您可以尝试从内容
属性访问第1页
对象电流框架
。事情是这样的:
You can try accessing Page1
object from Content
property of current Frame
. Something like this :
var currentFrame = Window.Current.Content as Frame;
var page1 = currentFrame.Content as Page1;
第1页的那么公共方法
将可使用从第1页
变量:
page1.SomePublicMethod();
这篇关于Windows 8应用从App.xaml.cs访问页面的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!