Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > Mobile > Windows Phone Dev - สอนเขียน App บนโปรแกรม Windows Phone 7 , Windows Phone 8 > การสร้าง Page และการ Link แสดงและซ่อน Uri Page Navigation บน Windows Phone



Clound SSD Virtual Server

การสร้าง Page และการ Link แสดงและซ่อน Uri Page Navigation บน Windows Phone

การสร้าง Page และการ Link แสดงและซ่อน Uri Page Navigation บน Windows Phone ใน Windows Phone หน้าแต่ล่ะหน้าจะเรียกว่า Page และในกรณีที่ใน Project มี Page อยู่มากว่า 1 ตัว ก็สามารถใช้การเปลี่ยนหน้าไปยัง Page ต่าง ๆ เหมือนกับการ Link ข้อมูลบน HTML ได้ง่าย ๆ ด้วยคำสั่ง
Uri("/Destination.xaml", UriKind.Relative)


ตัวอย่างการใช้งาน

คำสั่งเมื่อต้องการไปยัง Page ต่าง ๆ
NavigationService.Navigate(New Uri("/Page2.xaml", UriKind.Relative))

กรณีที่ต้องการย้อนกลับไป Page ก่อนนี้
avigationService.GoBack()


 Windows Phone Uri Page Navigatio


จากรูปเป็น Model การทำงาน โดยหลังจากที่ Application เปิดขึ้นมาจะแสดง Splash Screen จากนั้นจะเข้าสู่ Page 1 ซึ่งเป็น MainPage และสามารถคลิกไปยัง Page 2 และ Page 3

MainPage.xaml

 Windows Phone Uri Page Navigatio

MainPage.xaml
    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="Page 1" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Button Content="Goto Page 2" Height="72" HorizontalAlignment="Left" Margin="94,143,0,0" Name="btnGoPage2" VerticalAlignment="Top" Width="264" />
        </Grid>
    </Grid>


MainPage.xaml.vb (VB.NET)
Partial Public Class MainPage
    Inherits PhoneApplicationPage

    ' Constructor
    Public Sub New()
        InitializeComponent()
    End Sub


    Private Sub btnGoPage2_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnGoPage2.Click
        NavigationService.Navigate(New Uri("/Page2.xaml", UriKind.Relative))
    End Sub

End Class


MainPage.xaml.cs (C#)
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public partial class MainPage : PhoneApplicationPage
{

	// Constructor
	public MainPage()
	{
		InitializeComponent();
	}


	private void btnGoPage2_Click(System.Object sender, System.Windows.RoutedEventArgs e)
	{
		NavigationService.Navigate(new Uri("/Page2.xaml", UriKind.Relative));
	}

}









สร้าง Page ขึ้นมาใหม่ชื่อว่า Page2 และ Page3

 Windows Phone Uri Page Navigatio

คลิกขวาที่ Project -> Add -> New Items

 Windows Phone Uri Page Navigatio

เลือกเป็น Windows Phone Portrait Page และกำหนดชื่อเป็น Page2.xaml

 Windows Phone Uri Page Navigatio

ไฟล์ Page2.xaml และ Page2.xaml.vb แสดงบน Project

Page2.xaml

ออกแบบ Screen บน Page ของ Page2.xaml ดังภาพ

 Windows Phone Uri Page Navigatio

Page2.xaml
    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="Page 2" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Button Content="Goto Page 3" Height="72" HorizontalAlignment="Left" Margin="94,143,0,0" Name="btnGoPage3" VerticalAlignment="Top" Width="264" />
            <Button Content="GoBack MainPage" Height="72" HorizontalAlignment="Left" Margin="94,238,0,0" Name="btnGoBackMainPage" VerticalAlignment="Top" Width="264" />
        </Grid>
    </Grid>


Page2.xaml.vb (VB.NET)
Partial Public Class Page2
    Inherits PhoneApplicationPage

    Public Sub New()
        InitializeComponent()
    End Sub


    Private Sub btnGoPage3_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnGoPage3.Click
        NavigationService.Navigate(New Uri("/Page3.xaml", UriKind.Relative))
    End Sub

    Private Sub btnGoBackMainPage_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnGoBackMainPage.Click
        NavigationService.GoBack()
    End Sub
End Class


Page2.xaml.cs (C#)
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public partial class Page2 : PhoneApplicationPage
{

	public Page2()
	{
		InitializeComponent();
	}


	private void btnGoPage3_Click(System.Object sender, System.Windows.RoutedEventArgs e)
	{
		NavigationService.Navigate(new Uri("/Page3.xaml", UriKind.Relative));
	}

	private void btnGoBackMainPage_Click(System.Object sender, System.Windows.RoutedEventArgs e)
	{
		NavigationService.GoBack();
	}
}









สร้าง Page3.xaml เข้ามาใน Project

 Windows Phone Uri Page Navigatio

รายการ Page3.xaml และ Page3.xaml.vb เข้ามาใน Project

 Windows Phone Uri Page Navigatio

ออกแบบ Layout ด้วย Control ดังภาพ

Page3.xaml
    <!--LayoutRoot is the root grid where all page content is placed-->
    <Grid x:Name="LayoutRoot" Background="Transparent">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"/>
            <RowDefinition Height="*"/>
        </Grid.RowDefinitions>

        <!--TitlePanel contains the name of the application and page title-->
        <StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
            <TextBlock x:Name="ApplicationTitle" Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock x:Name="PageTitle" Text="Page 3" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
            <Button Content="Goto MainPage" Height="72" HorizontalAlignment="Left" Margin="94,143,0,0" Name="btnGoMainPage" VerticalAlignment="Top" Width="264" />
            <Button Content="GoBack Page 2" Height="72" HorizontalAlignment="Left" Margin="94,238,0,0" Name="btnGoBackPage2" VerticalAlignment="Top" Width="264" />
        </Grid>
    </Grid>


Page3.xaml.vb (VB.NET)
Partial Public Class Page3
    Inherits PhoneApplicationPage

    Public Sub New()
        InitializeComponent()
    End Sub

    Private Sub btnGoMainPage_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnGoMainPage.Click
        NavigationService.Navigate(New Uri("/MainPage.xaml", UriKind.Relative))
    End Sub

    Private Sub btnGoBackPage2_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnGoBackPage2.Click
        NavigationService.GoBack()
    End Sub

End Class


Page3.xaml.cs (C#)
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data;
using System.Diagnostics;
public partial class Page3 : PhoneApplicationPage
{
    
	public Page3() {
		InitializeComponent();
	}

	private void btnGoPage3_Click(System.Object sender, System.Windows.RoutedEventArgs e)
	{
		NavigationService.Navigate(new Uri("/Page3.xaml", UriKind.Relative));
	}

	private void btnGoBackMainPage_Click(System.Object sender, System.Windows.RoutedEventArgs e)
	{
		NavigationService.GoBack();
	}
}


Screenshot

 Windows Phone Uri Page Navigatio

สามารถคลิกไปยัง Goto Page 2

 Windows Phone Uri Page Navigatio

เมื่ออยู่ Page 2 สามารถ Goto Page 3 หรือ GoBack MainPage

 Windows Phone Uri Page Navigatio

เมื่ออยู่ Page 2 สามารถ GoBack Page 2 หรือ Goto MainPage


.

   
Share


ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท


ลองใช้ค้นหาข้อมูล


   


Bookmark.   
       
  By : ThaiCreate.Com Team (บทความเป็นลิขสิทธิ์ของเว็บไทยครีเอทห้ามนำเผยแพร่ ณ เว็บไซต์อื่น ๆ)
  Score Rating :  
  Create/Update Date : 2012-08-18 15:16:24 / 2017-03-25 21:42:28
  Download : Download  การสร้าง Page และการ Link แสดงและซ่อน Uri Page Navigation บน Windows Phone
 Sponsored Links / Related

 
Windows Phone and Grid จัดวาง Layout ด้วย RowDefinition และ ColumnDefinition
Rating :

 
Orientations Landscape มุมมอง Layout ในแนวตั้งและแนวนอนบน Windows Phone
Rating :

 
Margin Property และการจัดวาง Layout ในหน้า Silverlight Page, Windows Phone
Rating :

 
การเขียนโปรแกรมส่งค่า Parameter ข้าม Page ไปยัง Page ต่าง ๆ บน Windows Phone
Rating :

 
Custom Style เรียกใช้งาน Style บน Windows Phone (Style and StaticResource)
Rating :

 
รู้จักกับ Panorama Control บน Windows Phone Application
Rating :

 
รู้จักกับ Pivot Control บน Windows Phone Application
Rating :

 
Windows Phone การใช้งาน Panorama Control ร่วมกับ Pivot Control
Rating :


ThaiCreate.Com Forum


Comunity Forum Free Web Script
Jobs Freelance Free Uploads
Free Web Hosting Free Tools

สอน PHP ผ่าน Youtube ฟรี
สอน Android การเขียนโปรแกรม Android
สอน Windows Phone การเขียนโปรแกรม Windows Phone 7 และ 8
สอน iOS การเขียนโปรแกรม iPhone, iPad
สอน Java การเขียนโปรแกรม ภาษา Java
สอน Java GUI การเขียนโปรแกรม ภาษา Java GUI
สอน JSP การเขียนโปรแกรม ภาษา Java
สอน jQuery การเขียนโปรแกรม ภาษา jQuery
สอน .Net การเขียนโปรแกรม ภาษา .Net
Free Tutorial
สอน Google Maps Api
สอน Windows Service
สอน Entity Framework
สอน Android
สอน Java เขียน Java
Java GUI Swing
สอน JSP (Web App)
iOS (iPhone,iPad)
Windows Phone
Windows Azure
Windows Store
Laravel Framework
Yii PHP Framework
สอน jQuery
สอน jQuery กับ Ajax
สอน PHP OOP (Vdo)
Ajax Tutorials
SQL Tutorials
สอน SQL (Part 2)
JavaScript Tutorial
Javascript Tips
VBScript Tutorial
VBScript Validation
Microsoft Access
MySQL Tutorials
-- Stored Procedure
MariaDB Database
SQL Server Tutorial
SQL Server 2005
SQL Server 2008
SQL Server 2012
-- Stored Procedure
Oracle Database
-- Stored Procedure
SVN (Subversion)
แนวทางการทำ SEO
ปรับแต่งเว็บให้โหลดเร็ว


Hit Link
   







Load balance : Server 05
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่