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 > การเขียนโปรแกรมส่งค่า Parameter ข้าม Page ไปยัง Page ต่าง ๆ บน Windows Phone



Clound SSD Virtual Server

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

การเขียนโปรแกรมส่งค่า Parameter ข้าม Page ไปยัง Page ต่าง ๆ บน Windows Phone การส่งค่า ข้อความ String ระหว่าง Page บน Windows Phone จะใช้การส่งผ่าน URL คล้ายกับการส่งผ่านผ่าน GET และ QueryString บน Web (ASP.NET)

การส่งค่า
NavigationService.Navigate(new Uri("/SecondPage.xaml?msg=" + textBox1.Text, UriKind.Relative))

การรับค่า
Dim strName As String = ""
NavigationContext.QueryString.TryGetValue("msg", strName)


Example ทดสอบการส่งค่าตัวแปรระหว่าง 2 Page

MainPage.xaml
ออกแบบ Page ดังภาพด้วย Control ของ TextBlock,TextBox และ Button

Windows Phone Page Parameters

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="Send to Page 2" Height="72" HorizontalAlignment="Left" Margin="100,209,0,0" Name="btnSendToPage2" VerticalAlignment="Top" Width="264" />
            <TextBlock Height="62" HorizontalAlignment="Left" Margin="100,33,0,0" Name="txtTitle" Text="Input your name?" VerticalAlignment="Top" TextAlignment="Center" FontSize="32" Width="296" />
            <TextBox Height="72" HorizontalAlignment="Center" Margin="40,101,44,0" Name="txtName" VerticalAlignment="Top" Width="372" />
        </Grid>
    </Grid>


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

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


    Private Sub btnSendToPage2_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnSendToPage2.Click
        Dim strName As String
        strName = Me.txtName.Text
        NavigationService.Navigate(New Uri("/Page2.xaml?pName=" & strName, 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 class MainPage : PhoneApplicationPage {
    
    //  Constructor
    public MainPage() {
        InitializeComponent();
    }
    
    private void btnSendToPage2_Click(object sender, System.Windows.RoutedEventArgs e) {
        string strName;
        strName = this.txtName.Text;
        NavigationService.Navigate(new Uri(("/Page2.xaml?pName=" + strName), UriKind.Relative));
    }
}









Page2.xaml
ออกแบบ Page สำหรับหรับค่าตัวแปรจาก Page แรก

Windows Phone Page Parameters

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="GoBack MainPage" Height="72" HorizontalAlignment="Left" Margin="94,238,0,0" Name="btnGoBackMainPage" VerticalAlignment="Top" Width="264" />
            <TextBlock Height="82" HorizontalAlignment="Left" Margin="179,39,0,0" Name="lblTitle" Text="Hello" VerticalAlignment="Top" FontSize="48" />
            <TextBlock Height="78" HorizontalAlignment="Right" Margin="0,124,127,405" Name="lblName" Text="Name" VerticalAlignment="center" FontSize="48" Foreground="#FFF2410C" Width="138" />
        </Grid>
    </Grid>


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

    Public Sub New()
        InitializeComponent()
        AddHandler Loaded, AddressOf Page2_Loaded
    End Sub

    Private Sub Page2_Loaded(sender As Object, e As System.Windows.RoutedEventArgs)
        Dim strName As String = ""
        NavigationContext.QueryString.TryGetValue("pName", strName)

        Me.lblName.Text = strName
    End Sub

    Private Sub btnGoPage3_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
        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 class Page2 : PhoneApplicationPage {
    
    public Page2() {
        InitializeComponent();
        Loaded += Page2_Loaded;
    }
    
    private void Page2_Loaded(object sender, System.Windows.RoutedEventArgs e) {
        string strName = "";
        NavigationContext.QueryString.TryGetValue("pName",out strName);
        this.lblName.Text = strName;
    }
    
    private void btnGoPage3_Click(object sender, System.Windows.RoutedEventArgs e) {
        NavigationService.Navigate(new Uri("/Page3.xaml", UriKind.Relative));
    }
    
    private void btnGoBackMainPage_Click(object sender, System.Windows.RoutedEventArgs e) {
        NavigationService.GoBack();
    }
}


Screenshot

Windows Phone Page Parameters

กรอกข้อมูลในช่อง Textbox และคลิกที่ Send to Page 2

Windows Phone Page Parameters

แสดงค่าตัวแปรที่ส่งมาจาก Page 1







.

   
Share


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


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


   


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

 
การสร้าง Page และการ Link แสดงและซ่อน Uri Page Navigation บน 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 01
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 อัตราราคา คลิกที่นี่