locked
How to dynamically change content in the MainPage? RRS feed

  • Question

  • Hello,

    I have created MainPage.xaml which is a UserControl that comprises of an image and a few other controls for the header and a Frame control.  I am able to display and navigate between different pages using NavigationService.Navigate.

    My first page is a login page and I would like the header defined in the main page to not be displayed.

    I tried to solve this by obtaining a reference to the MainPage within the login page's OnNavigatedTo event and setting the header controls to invisible but the header controls are displayed briefly on the login page before disappearing?

    Can you please tell me how I can dynamically change the content of the MainPage.xaml depending on which page is being displayed within the Frame?

    I don't really understand the page life cycle and the events that occur between when the MainPage is set as the RootVisual in the App class and the display of the subsequent pages.

    Thanks.

    Thursday, August 5, 2010 12:09 PM

Answers

  • Hi,

    I realised that what I needed to do was handle the frame navigating event and set visibility of header depending on the page that is being navigated to.

    Thanks for your help.

     

     

    Thursday, August 5, 2010 3:13 PM

All replies

  • You can set a public method in MainPage.xaml to make the appropriate changes (toggle visibility or ui changes).  When the individual page loads, you can call this public method through App's RootVisual. 

    In the following example, we are calling the Refresh method in MainPage.xaml.cs. 

    ((App.Current as App).RootVisual as MainPage).Refresh();


     

    Thursday, August 5, 2010 12:21 PM
  • Hi,

    I have added a public method in MainPage.xaml which hides the header.

    In the OnNavigatedTo event handler in the Login.xaml page, I call the method as follows:

    ((App.Current as App).RootVisual as MainPage).HideHeader();

    When the login page is displayed for the first time, the header is briefly displayed before being hidden which is not correct.

    Is there perhaps another event handler in which I should be hiding the header so I don't see any 'flicker'.

    Thanks.

     

     

    Thursday, August 5, 2010 12:51 PM
  • Do you want the header to be shown by default? If not, then  you can set the control (header)'s visibility to collapsed in the xaml or the MainPage.xaml.cs's constructor.

    Thursday, August 5, 2010 2:28 PM
  • Hi,

    I realised that what I needed to do was handle the frame navigating event and set visibility of header depending on the page that is being navigated to.

    Thanks for your help.

     

     

    Thursday, August 5, 2010 3:13 PM