How to pass data between wpf page and a window

Total Post:88

Points:616
WPF
 6694  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. 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.

      Modified On Mar-31-2018 01:39:14 AM

Answer

NEWSLETTER

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