WPF multi-window-pass Solution

Source: Internet
Author: User

In WPF, we often involve the problem of passing parameters between multiple windows, so how do we pass them?

A : in the window's constructor, add the arguments that you want to pass. (If I'm not good at it, see the code below.) )

In the main window, a single button opens a new child window.

The main window class section is as follows: public partial class Mainwindow:window    {public        MainWindow ()        {            InitializeComponent ();        }        private void Button_Click (object sender, RoutedEventArgs e)        {            NewWindow NewWindow = new NewWindow (string str);            Newwindow.showdialog ();        }    }

The child window class is as follows:

public partial class Newwindow:window    {public        string str{get; set;}        Public NewWindow (String  strref)        {            str = strref;            InitializeComponent ();                    }       You can refer to the STR variable.          }

  Note: If we pass the parameter as a value type (int,char,double) , then the data is passed in one direction, that is, from the parent window to the child window only.

Therefore, if you want to implement a parent window that can pass arguments to each other between child windows, then we must do so by passing a variable of the reference type (except for the string type).

As for why, it should be the result of parameter passing at the bottom of the operation. (It may be the same as in c,c++, that is, a copy of the passed parameter is passed through,

I guess. May not be the same as the underlying operation, but at least the appearance is the same. )

WPF multi-window-pass Solution

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.