WPF child interfaces pass a delegate with parameters to the parent interface

Source: Internet
Author: User

The requirements are as follows:

There are several buttons on the parent interface that need to be passed to the parent interface when the button is clicked to know which interface the control is displayed in.

Parent interface: WIN1

Sub-Interface: WIN2

This, or the child control, passes the value to the parent control

1. Sub-Interface Definition delegate

WIN1 wrote:

public delegate void Changetexthandler (string text);

public event Changetexthandler Changetextevent;

2. Parent interface after the child interface is loaded, register the delegate. Must be registered when the parent interface is load or before

WIN2 wrote:

Ucsetting1.changetextevent + = new Control.ucSetting.ChangeTextHandler (showmessage);

Here ucSetting1 is the name of the child control

3. Then write the corresponding implementation function in the parent interface ShowMessage

It's still in WIN2.

private void ShowMessage (string msgx)

{

Switch (MSGX)

{

Dosth

}

}

4. After the end, write the function that triggers the delegate in the sub-interface.

Write in WIN1:

public string text;

Text = "Systemsettingcontrol"

if (changetextevent! = null)

{

Changetextevent (text);

}

The interface then executes the corresponding function in the parent interface based on the parameters passed in.

In fact, it is quite simple, it is not difficult to get the words

WPF child interfaces pass a delegate with parameters to the parent interface

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.