Home > DeveloperSection > Forums > How to pass data between wpf page and a window
jacob rasel
jacob rasel

Total Post:88

Points:616
Posted on    September-23-2013 7:56 AM

 WPF
Ratings:


 1 Reply(s)
 4923  View(s)
Rate this:

I'm developing a WPF and C# application and i have problems to pass data between a page and a window.

How is the best way to do it?

Thanks!



Pravesh Singh

Total Post:411

Points:2881
Posted on    September-23-2013 8:25 AM

Hi Jacob,

You can use a delegateevent to do this.

 For example in your MainWindow :

namespace WpfApplication1

{

public partial class MainWindow : Window

{

    public MainWindow()

    {

        InitializeComponent();

        Page1.onNameSend += Page1_onNameSend;

    }

    void Page1_onNameSend(string Name)

    {

        Console.WriteLine(Name);

    }

}

}

And then in your Page1:

namespace WpfApplication1

{

public partial class Page1 : Page

{

    public delegate void SendName(string Name);

    public static event SendName onNameSend;

    public Page1()

    {

        InitializeComponent();

    }

    private void SendButton(object sender, RoutedEventArgs e)

    {

        onNameSend("Name to Send");

    }

}

}

Hope that helps.


Don't want to miss updates? Please click the below button!

Follow MindStick