2016-06-02 6 views
0

Cortana를 사용하여 UWP 앱에 사용하고 있습니다. 정상적으로 작동합니다. 그러나 app.xaml.cs에없는 메소드를 호출하려고하면 실패합니다.UWP Cortana - MyClass.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(); 

내가 어떻게 액세스 할 수 있습니까?

도움 주셔서 감사합니다.

답변

0

자신에 의해 그것을 해결 :

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();