简体   繁体   中英

How to load content page into mainPage from another xaml page?

I have 3 separate pages MainPage.xaml, Content.xaml and Nav.xaml. I need to load a Content.xaml in 'ucMainContent' userControl that sits inside MainPage.xaml by clicking a button from Nav.xaml. I am wondering what I am doing wrong. Any advice is highly appreciated.

MainPage.xaml where I set content container with this code:

<UserControl x:Name="ucMainContent" />

I am trying to load Content.xaml into mainPage.xaml from Nav.xaml. The code from Nav.xaml page where is the button:

private void LoadContent_MouseLeftButtonUp(object sender, System.Windows.Input.MouseButtonEventArgs e)
    {
        var contentPage = new Content();
        var ucMainPage = new MainPage();
        ucMainPage.ucMainContent.Content = contentPage;
    }

If I understand you correctly you need to find the parent Control of Nav.xaml in this case Main.

Check out http://forums.silverlight.net/forums/t/55369.aspx - there is an excellent generic utility which allows you to find the parent of any usercontrol

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