UWP Cortana — как получить доступ к методам в MyClass.xaml.cs?

Я использую Cortana для своего приложения UWP, и он отлично работает. Но когда я пытаюсь вызвать методы, которых нет в app.xaml.cs, я терплю неудачу.

Что я пытаюсь сделать:

// Switch the content of my Frame (works so far)
Frame rootFrame = Window.Current.Content as Frame;
MainPage page = rootFrame.Content as MainPage;
// cframe references my XAML Frame in the MainPage
page.cframe.Navigate(typeof(MyClass));
// Now the content of the frame is changed and I want to call a method from
// MyClass.xaml.cs
MyClass p = rootFrame.Content as MyClass;
// Here I get a System.NullReferenceException when I try to call
// the "callWebservice()" method from MyClass.xaml.cs
p.callWebservice();

Как я могу получить доступ?

Спасибо за помощь.


person pyTh0n-M4nning    schedule 02.06.2016    source источник


Ответы (1)


Решил сам:

Frame rootFrame = Window.Current.Content as Frame;
MainPage page = rootFrame.Content as MainPage;
page.cframe.Navigate(typeof(MyClass));
//the next line do the trick
MyClass p = page.cframe.Content as MyClass;
p.callWebservice();
person pyTh0n-M4nning    schedule 02.06.2016