如何从 App class 访问 MainPage class 非静态成员?
How do I access MainPage class non-static members from the App class?
我根据 MSDN 文档 https://msdn.microsoft.com/en-us/library/windows/apps/hh394038(v=vs.105).aspx. I have added event handlers encapsulated within the App class to each of the buttons in the application bar. I need a way of accessing the current instance of MainPage class from the App class so I may call non-static methods in the MainPage class to update the UI. I have Binged for hours but I have not come across a solution. I came across this answer 在我的空白处添加了一个应用程序栏 Windows Phone 8.1 Silverlight 应用程序 https://msdn.microsoft.com/en-us/library/windows/apps/hh394038(v=vs.105).aspx. I have added event handlers encapsulated within the App class to each of the buttons in the application bar. I need a way of accessing the current instance of MainPage class from the App class so I may call non-static methods in the MainPage class to update the UI. I have Binged for hours but I have not come across a solution. I came across this answer 但它回答的问题与我的问题有点相反.可悲的是,解决方案不是。你能帮忙吗?
我会使用 Reactive Extensions (RX) 来解决这个问题。
您可以使用 NuGet 将 Reactive Extensions (RX) 添加到您的项目,搜索 rx-main
并安装 Reactive Extensions - Main Library
。
您的两个页面都将访问一个公共的 class,而该 class 将具有 Subject<T>
。一个页面将使用 OnNext
向此 Subject<T>
发布事件,而另一个页面将使用 Subscribe
订阅这些事件。
有关完整的示例,请参阅 Rx how to create a sequence from a pub/sub pattern。
我根据 MSDN 文档 https://msdn.microsoft.com/en-us/library/windows/apps/hh394038(v=vs.105).aspx. I have added event handlers encapsulated within the App class to each of the buttons in the application bar. I need a way of accessing the current instance of MainPage class from the App class so I may call non-static methods in the MainPage class to update the UI. I have Binged for hours but I have not come across a solution. I came across this answer 在我的空白处添加了一个应用程序栏 Windows Phone 8.1 Silverlight 应用程序 https://msdn.microsoft.com/en-us/library/windows/apps/hh394038(v=vs.105).aspx. I have added event handlers encapsulated within the App class to each of the buttons in the application bar. I need a way of accessing the current instance of MainPage class from the App class so I may call non-static methods in the MainPage class to update the UI. I have Binged for hours but I have not come across a solution. I came across this answer 但它回答的问题与我的问题有点相反.可悲的是,解决方案不是。你能帮忙吗?
我会使用 Reactive Extensions (RX) 来解决这个问题。
您可以使用 NuGet 将 Reactive Extensions (RX) 添加到您的项目,搜索 rx-main
并安装 Reactive Extensions - Main Library
。
您的两个页面都将访问一个公共的 class,而该 class 将具有 Subject<T>
。一个页面将使用 OnNext
向此 Subject<T>
发布事件,而另一个页面将使用 Subscribe
订阅这些事件。
有关完整的示例,请参阅 Rx how to create a sequence from a pub/sub pattern。