• 0

C# Win8 Store: access parent xaml from object


Question

Hello gang,

I am creating a WIn8 store app and with that a basic class that will do the majority of work. I want this class to call back to the MainPage.xaml to access objects placed within it.

For example in the app.xaml.cs I have the following code


private BediaEngine objBediaEngine;

public App()
{
this.InitializeComponent();
this.Suspending += OnSuspending;

objBediaEngine = new BediaEngine()
}

[/CODE]

I thought I recall somewhere that I need to pass the parent into the class with the "this" keyword.

[CODE]
objBediaEngine = new BediaEngine(this);
[/CODE]

I am close, I believe, but I could use a point to a page that gives me some details.

Thanks

Link to comment
Share on other sites

2 answers to this question

Recommended Posts

  • 0

I'm not sure I understand what the problem is, but "this" is the current object instance in any non-static method or constructor, exactly like "Me" in Visual Basic. So if you're creating your "BediaEngine" from the MainPage constructor you indeed need to pass "this" as a parameter to give it a reference to that MainPage. Does that help?

Link to comment
Share on other sites

  • 0

Ever mind, got it. I was placing the following in app.xaml.cs instead of MainPage.xml (oops)

objBediaEngine = new BediaEngine(this);

Link to comment
Share on other sites

This topic is now closed to further replies.