1 year ago
#386933

Bishiba
UWP C#: How to / Possible to: Refer to Page instance without creating a variable?
2-3 weeks into the UWP part of the C# course now. And I am faced more and more with a dilemma that I am not a fan of. I've created 2 public static variables on the MainPage for holding instances of Pages so I can reach their respective public methods.
Essentially I have the MainPage variable as follows:
public sealed partial class MainPage : Page {
public static OtherPage otherPage = null;
}
Then, upon initializing the other Page, I do this:
public OtherPage() {
this.InitializeComponent();
MainPage.otherPage = this;
}
And, I always do things not even mentioned in the course literature, just more fun to create my own projects and kind of push to boundaries for what I understand by experimenting with what I can come up with. But this often leads to the situations where I know there are better ways to do things. And this seems to me like one of this situations, really feels like there should be some way to access all loaded/active pages.
Best regards!
c#
uwp
0 Answers
Your Answer