Click here to Skip to main content
15,884,472 members
Articles / Desktop Programming / WPF

Navigation in MVVM applications (Onyx)

Rate me:
Please Sign up or sign in to vote.
4.33/5 (7 votes)
13 Nov 2009CPOL4 min read 69.9K   2.2K   28  
Navigation in MVVM applications. Combined with navigation through DataTemplates, navigation through NavigationService provides a richer toolkit for WPF developers. I think it would be useful to utilize NavigationService, since the development of WPF applications then becomes similar to web developme
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using System.Windows.Navigation;

namespace testUnit
{
    public partial class TestForm : Form
    {
        private NavigationWindow nw;
        private Uri uri;

        public TestForm()
        {
            InitializeComponent();

            nw = new NavigationWindow();

            try
            {
                uri = new Uri("pack://application:,,,/NavigationDemo;component/Page1.xaml", UriKind.Absolute);
                nw.Navigate(uri);
                nw.Show();
            }
            catch (Exception ex) {}
        }

        private void button_page1_Click(object sender, EventArgs e)
        {
            try
            {
                uri = new Uri("pack://application:,,,/NavigationDemo;component/Page1.xaml", UriKind.RelativeOrAbsolute);
                nw.Navigate(uri);
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }

        private void button_page2_Click(object sender, EventArgs e)
        {
            try
            {
                uri = new Uri("pack://application:,,,/NavigationDemo;component/Page2.xaml", UriKind.RelativeOrAbsolute);
                nw.Navigate(uri);
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }

        private void button_page3_Click(object sender, EventArgs e)
        {
            try
            {
                uri = new Uri("pack://application:,,,/NavigationDemo;component/Page3.xaml", UriKind.RelativeOrAbsolute);
                nw.Navigate(uri);
            }
            catch (Exception ex) { MessageBox.Show(ex.Message); }
        }
    }
}

By viewing downloads associated with this article you agree to the Terms of Service and the article's licence.

If a file you wish to view isn't highlighted, and is a text file (not binary), please let us know and we'll add colourisation support for it.

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Russian Federation Russian Federation
I have Master degree in Particle Physics. During my last several years I work as software developer.

Primary Interests
- c#, c++, php, java.
- scientific programming

Comments and Discussions