简体   繁体   中英

How to Target the current frame in Silverlight using C#?

If I have a button in a navigation page, how do I make it target the frame that it is in?

For example, I have a frame called navFrame in MainPage.xaml and I have a navigation page in the Views folder called Home.xaml with a button on it. Basically I'm trying to make clicking the button Home.xaml target the navFrame in MainPage.xaml.

Is that possible? for the button code I tried using MainPage.navFrame.Navigate(...) but it gave me the error "an object is required to reference a non static property..." but I don't know what kind of object it wants or how I would use it.

I'm sorry if this is a stupid question. I'm new to all of this and I spent all last night trying to figure out. Any help would be really appreciated!

From the error message it seems that you don't have a reference to the instance of MainPage in the Home class.

You could get a reference to it through searching up the Visual Tree or calling Application.Current.RootVisual or using some kind of locator framework.

But you don't really need to get a reference to MainPage. From inside the Home : Page class you could instead try

this.NavigationService.Navigate(new Uri("/About", UriKind.Relative))

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM