HOW TO PASS DATA BETWEEN WPF PAGE AND A WINDOW

jacob rasel

Total Post:88

Points:616
Posted by  jacob rasel
WPF
 6230  View(s)
Ratings:
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!

  1. Pravesh Singh

    Post:412

    Points:2888
    Re: How to pass data between wpf page and a window

    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.

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!