Data Passing in Windows Phone Application



On the main page of your project add a StackPanel. Within this StackPanel add one TextBox and two Buttons as shown in the xaml code below:
  <StackPanel>
        <TextBox InputScope="Chat" Name="TextBoxUsername"></TextBox>
        <Button Click="Button_Click">Signup</Button>
        <Button Click="click_again">Again</Button>
    </StackPanel>

The designer view and the xaml code is shown below


The code for the xaml.cs file is as below:


namespace Data_Passing
{
    public partial class MainPage : PhoneApplicationPage
    {
        // Constructor
        public MainPage()
        {
            InitializeComponent();

            // Sample code to localize the ApplicationBar
            //BuildLocalizedApplicationBar();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {

            NavigationService.Navigate(new Uri("/Page1.xaml?key1=" + TextBoxUsername.Text, UriKind.Relative));
        }

        private void click_again(object sender, RoutedEventArgs e)
        {
            NavigationService.Navigate(new Uri("/Page1.xaml?id=asdf", UriKind.Relative));
        }

    }
}


Now the xaml code for the second page is as follows:
<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 Grid.Row="0" Margin="12,17,0,28">
            <TextBlock Text="MY APPLICATION" Style="{StaticResource PhoneTextNormalStyle}"/>
            <TextBlock Name="TextBlockUsername" Text="" Margin="9,-7,0,0"
                       Style="{StaticResource PhoneTextTitle1Style}"/>
            <Button Click="test_page">check Value</Button>
        </StackPanel>

        <!--ContentPanel - place additional content here-->
        <Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">

        </Grid>
    </Grid>

The designer view and the xaml code for the second page is shown below:


 

Data Passing in Windows Phone Application Data Passing in Windows Phone Application Reviewed by Afsar Murad on 12:10 Rating: 5
Powered by Blogger.