Reputation: 43
Probably a stupid question so I apologise in advance. I am new to building a Windows 8 Store App.
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.
How can I create a reference to my Page1 script?
Upvotes: 4
Views: 817
Reputation: 3676
Sometimes you gotta run it main thread if code is being triggered from another thread, This worked for me.
Windows.ApplicationModel.Core.CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal, () =>
{
try
{
ProjectsPage projectsPage = (Window.Current.Content as AppShell).AppFrame.Content as ProjectsPage;
projectsPage.FetchProjects();
}
catch (Exception ex)
{
}
});
this worked for me
Upvotes: 0
Reputation: 89305
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;
Then public methods of Page1
will be accessible from page1
variable :
page1.SomePublicMethod();
Upvotes: 4