Navigation Basics : NavigationWindow « Windows Presentation Foundation « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » Windows Presentation Foundation » NavigationWindow 
24.75.1.Navigation Basics
<NavigationWindow
    x:Class="WpfApplication1.Window1"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="NavigationBasics"
    Height="300"
    Width="300">
</NavigationWindow>
//File:Window.xaml.cs
using System;
using System.Collections.Generic;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Navigation;
using System.Windows.Documents;
using System.Diagnostics;


namespace WpfApplication1 {
  public partial class Window1 : NavigationWindow {
    Hyperlink link1 = new Hyperlink();
    Hyperlink link2 = new Hyperlink();
    TextBlock text1 = new TextBlock();
    TextBlock text2 = new TextBlock();

    public Window1() {
      InitializeComponent();
      text1.Inlines.Add(link1);
      text1.VerticalAlignment = VerticalAlignment.Bottom;
      text1.Loaded += text1_Loaded;

      link1.Inlines.Add("Click to see page 2");
      link1.Click += link1_Click;

      text2.Inlines.Add(link2);
      text2.VerticalAlignment = VerticalAlignment.Bottom;
      text2.Loaded += text2_Loaded;

      link2.Inlines.Add("Click to go back to page 1");
      link2.Click += link2_Click;

      this.Navigate(text1);


      Button button1 = new Button();
      Button button2 = new Button();

      button1.Content = "Click to see Button 2";
      button1.Loaded += delegate(object sender, RoutedEventArgs e2) {
          ((NavigationWindow)button1.Parent).Title = "Welcome to button1";
      };
      button1.Click += delegate(object sender, RoutedEventArgs e2) {
          this.Navigate(button2);
      };
      button2.Content = "Click to go back to Button 1";
      button2.Loaded += delegate(object sender, RoutedEventArgs e2) {
          ((NavigationWindow)button2.Parent).Title = "Welcome to button2";
      };
      button2.Click += delegate(object sender, RoutedEventArgs e2) {
         ((NavigationWindow)button2.Parent).GoBack();
      };

      this.Navigate(button1);
    }

    void text1_Loaded(object sender, RoutedEventArgs e) {
      Title = "Welcome to Page 1";
    }

    void text2_Loaded(object sender, RoutedEventArgs e) {
      Title = "Welcome to Page 2";
    }

    void link1_Click(object sender, RoutedEventArgs e) {
      Navigate(text2);
    }

    void link2_Click(object sender, RoutedEventArgs e) {
      NavigationService navService = NavigationService.GetNavigationService((DependencyObject)sender);
      navService.GoBack();
    }
  }
}
WPF Navigation Basics
24.75.NavigationWindow
24.75.1.Navigation BasicsNavigation Basics
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.