Email: Password:       Forgot Password 
    .netCodeSG
A Saarsha Group Online Community for dot net codes group like C#, Asp.NET, VB.NET, Sharepoint, JavaScript, JQuery, Ajax, SQL, WCF, WPF.
 
TECHNOLOGIES:
 

Send Value From One Page To Another Page in WPF

Article:
Viewed:  3391 
Posted On:  03/10/2012 19:01:02 
In this article I am going to show how we can send any value from one form to another form in WPF 

In this article I am going to show how we can send value from one window to other window in WPF.

Below is my Window1.xaml code.

<Window x:Class="SendValueFromAnotherPageInWPF.Window1"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"    Title="Window1" Height="300" Width="300">
    <Grid>
        <Button Content="Submit" Height="23" Margin="87,89,116,0" Name="SubmitBtn" VerticalAlignment="Top" Click="SubmitBtn_Click" />
        <TextBox Height="23" Margin="30,46,43,0" Name="textBox1" VerticalAlignment="Top" />
        <Label Content="Enter your name here" Height="28" HorizontalAlignment="Left" Margin="26,12,0,0" Name="label1" VerticalAlignment="Top" />
    </Grid>
</Window> 

Window1.XAML.cs code.

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes; 

namespace SendValueFromAnotherPageInWPF
{

    /// <summary>
    /// Interaction logic for Window1.xaml
    /// </summary>

    public partial class Window1 : Window
    {
        public Window1()
        {
            InitializeComponent();
        } 

        private void SubmitBtn_Click(object sender, RoutedEventArgs e)
        {
            Window2 mySeconPage = new Window2();
            mySeconPage.TextBlockName.Text = textBox1.Text;
            mySeconPage.Show();
            Close();
        }
    }
}

Now this is my Window2.xaml code

<Window x:Class="SendValueFromAnotherPageInWPF.Window2"    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    Title="Window2" Height="300" Width="300">
    <Grid>
        <TextBlock Height="23" HorizontalAlignment="Left" Margin="10,10,0,0" x:Name="WelcomeHeading" Text="Welcome:" VerticalAlignment="Top" FontSize="17" FontStretch="ExtraCondensed"/>

   <TextBlock Height="23" HorizontalAlignment="Left" Margin="90,10,0,0" x:Name="TextBlockName" VerticalAlignment="Top" FontSize="15" FontStretch="ExtraCondensed" />

</Grid>
</Window>

 When Run the application.

SendData1.png

Image 1.

SendData2.png

Image 2.

  Comment:
         HOME   |   Submit Article   |   Contact Us   |   About Us   |   Terms & Condition   |   Advertise With us