Windows 8 Application using the page method from App.xaml.cs

Probably a stupid question, so I apologize in advance. I am new to creating an application for the Windows 8 Store.

I need to run some methods on my script page when the application is paused. I have only one page, and I have 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 some text files are saved.

How to create a link to my Page 1 script?

+4
source share
2 answers

Page1 Content Frame. - :

var currentFrame = Window.Current.Content as Frame;
var page1 = currentFrame.Content as Page1;

Page1 Page1:

page1.SomePublicMethod();
+4

, . .

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)
            {
            }
    });

0

Source: https://habr.com/ru/post/1524195/


All Articles