【问题标题】:How to access App class from any page in Windows phone 8.1 sliverlight application?如何从 Windows phone 8.1 silverlight 应用程序中的任何页面访问 App 类?
【发布时间】:2015-08-14 10:47:01
【问题描述】:

我在 windows phone 8.1 sliverlight 的应用程序级别定义了一些属性。现在我想从任何页面获取 app.xaml.cs 的对象,就像我们可以在 android 中获取应用程序类一样。如果有人知道,请告诉我。

【问题讨论】:

    标签: silverlight windows-phone-8.1 windows-phone win-phone-silverlight-8.1


    【解决方案1】:

    如果我没记错的话,App 类是静态的,这意味着您可以像这样在页面中调用它

    App.MyProperty
    

    只要确保你的属性static

    如果你有很多东西想要访问,只需创建一个新的静态类并在那里添加所有内容,就像我上面提到的那样

    【讨论】:

    • @ViralThakker 虽然这不是问题,但我建议您采用我建议的第二种方式。作为一种实践,我希望尽可能保持 App.cs 文件“干净”,并始终创建另一个类来存储一些值
    猜你喜欢
    • 2014-09-07
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-06-06
    • 1970-01-01
    • 1970-01-01
    • 2015-05-05
    • 1970-01-01
    相关资源
    最近更新 更多