【问题标题】:UWP Cortana - How to access methods in MyClass.xaml.cs?UWP Cortana - 如何访问 MyClass.xaml.cs 中的方法?
【发布时间】:2016-10-02 07:09:15
【问题描述】:

我正在为我的 UWP 应用程序使用 Cortana,它运行良好。 但是当我尝试调用不在 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();

如何访问?

感谢您的帮助。

【问题讨论】:

    标签: uwp windows-10-universal cortana


    【解决方案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();
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-07-16
      • 1970-01-01
      • 2017-07-14
      • 1970-01-01
      • 1970-01-01
      • 2016-07-22
      • 2018-07-14
      • 1970-01-01
      相关资源
      最近更新 更多