none
WPF Changing a page

    Frage

  • Hi

    I've just finished the C# course and worked with Visual basic before, got a basic understanding of classes etc.

    Now got most of the code working but for the life of me a cannot find a way to navigate between pages with the WPF Application project, just added an extra page with a button but tried everything from navigatecommand to some code in the XAML.

    Where is the best place to put this navigation and can somebody please explain to me with an example how to navigate to another page using C#?

    Sorry for the stupid question, but I've been reading now for the last couple of hours are getting really desperate now.

    Regards,

    Montag, 3. September 2012 21:50

Antworten

  • Hi labjac

    Please have a look at this MSDN Samples project, for everything you need to know about NavigationService, with examples:

    http://code.msdn.microsoft.com/How-to-Build-Manage-and-fdd0074a

    Best regards,
    Pete


    #PEJL


    Montag, 3. September 2012 22:03
  • Firstly, if your "SystemIntegratorsMain" has any parameters in the constructor, that is what is causing your error, you have to create the Page first in code then navigate to that object:

    var ctl = new SystemIntegratorsMain(param1, param2);
    test.Navigate(ctl);

    HOWEVER, I notice the parent control is a Window. Are you hosting a Frame inside the Window? The navigation service would be looking for the Frame, it cannot navigate from a Window to a Page, you Navigate from Page to Page inside a Frame control, or a NavigationWindow.

     

    Please re-examine my samples project and check where your setup differs from that.

    Otherwise please post a complete example of your problem. BTW don't forget to mark any posts that have been helpful, or part answer ;)

     

    Regards,
    Pete


    #PEJL

    Samstag, 8. September 2012 18:49

Alle Antworten

  • Hi labjac

    Please have a look at this MSDN Samples project, for everything you need to know about NavigationService, with examples:

    http://code.msdn.microsoft.com/How-to-Build-Manage-and-fdd0074a

    Best regards,
    Pete


    #PEJL


    Montag, 3. September 2012 22:03
  • Hi

    Thanks I had a look at the project but this again is for Visual basic, I'm currently using C#, so not helping much..

    I'm looking for something similar to "page1.show"

    Regards,


    labjac

    Montag, 3. September 2012 22:09
  • Hi labjac,

    We use NavigationService class to navigate between pages in WPF, you can check out below links for detail information about it:

    http://msdn.microsoft.com/en-us/library/ms750478.aspx

    http://miteshsureja.blogspot.com/2012/03/wpf-page-navigation.html

    Hope it helps.

    Have a nice day.


    Annabella Luo[MSFT]
    MSDN Community Support | Feedback to us

    Mittwoch, 5. September 2012 06:21
  • Hi

    Thanks I had a look at the project but this again is for Visual basic, I'm currently using C#, so not helping much..

    I'm looking for something similar to "page1.show"

    Regards,


    labjac

    My MSDN project IS C#, and the answer is definitely to use NavigationService. The project shows several ways to do it.

    .Show() is a Window method, for opening windows, not navigating between Pages.

    If you are using Pages, the answer is NavigationService

     

    Best regards,
    Pete


    #PEJL

    Mittwoch, 5. September 2012 09:08
  • Hi Pete

    Thanks for the link.. please have a look at my Code below, I got two pages one called Main and the other SystemIntegratorsMain so I got a button on the main Page that O would like when operator press to goto the SystemIntegratorsMain, but below code is complaining about the Constructors that needs a value, not sure where I'm going wrong.

    namespace OM_Project_V2
    {
        /// <summary>
        /// Interaction logic for MainWindow.xaml
        /// </summary>
        public partial class MainWindow : Window
        {
            public MainWindow()
            {
                InitializeComponent();
            }
    
            private void BtnSiMain_Click(object sender, RoutedEventArgs e)
            {
                NavigationService test = new NavigationService();
                    {
                    test.Navigate("SystemIntegratorsMain");
                    }
           
                              
            }
        }


    labjac

    Freitag, 7. September 2012 19:35
  • Firstly, if your "SystemIntegratorsMain" has any parameters in the constructor, that is what is causing your error, you have to create the Page first in code then navigate to that object:

    var ctl = new SystemIntegratorsMain(param1, param2);
    test.Navigate(ctl);

    HOWEVER, I notice the parent control is a Window. Are you hosting a Frame inside the Window? The navigation service would be looking for the Frame, it cannot navigate from a Window to a Page, you Navigate from Page to Page inside a Frame control, or a NavigationWindow.

     

    Please re-examine my samples project and check where your setup differs from that.

    Otherwise please post a complete example of your problem. BTW don't forget to mark any posts that have been helpful, or part answer ;)

     

    Regards,
    Pete


    #PEJL

    Samstag, 8. September 2012 18:49