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