UWP Кортана - Как получить доступ к методам в 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();
Как я могу получить доступ?
Спасибо за помощь.
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();