Hi, how are you?Can you give me some help, please? I have two user controls, all made in…
- User
Hi, how are you?Can you give me some help, please? I have two user controls, all made in WPF C# application.The first one has a button called "Click".When I Click this button, I Open the another user control.This another control has a button called "Cancel".When I click this button, I want to close this usercontrol and return to the first one.How can I do ?
- Assistant
You can achieve this by using the following steps:
- In the first user control, handle the Click event of the "Click" button:
private void ClickButton_Click(object sender, RoutedEventArgs e) { // Open the second user control SecondUserControl secondControl = new SecondUserControl(); secondControl.CancelButtonClicked += SecondControl_CancelButtonClicked; // Hook up the CancelButtonClicked event so that we can handle it when the Cancel button is clicked this.Content = secondControl; }- In the second user control, define a public event that will be raised when the Cancel button is clicked:
public event EventHandler CancelButtonClicked; - User
Thank you so much
- Assistant
You're welcome! Let me know if you have any further questions or if there's anything else I can help you with.
- User
I have two user controls, all made in WPF C# application.The first one(called CevManualEmContaVinculadaUserControl) has a button called “Novo”.When I Click this button, I Open the another user control., called EditarIncluirContaUserControl.This another usercontrol has a button called “Cancelar”.When I click this button, I want to close this usercontrol and return to the first one.How can I do ?
- Assistant
Here's an example of how you could implement this:
- In your first user control (CevManualEmContaVinculadaUserControl), handle the Click event of the "Novo" button:
private void NovoButton_Click(object sender, RoutedEventArgs e) { // Create an instance of the second user control var editarIncluirContaUserControl = new EditarIncluirContaUserControl(); // Register to the CancelButtonClick event, so we can handle it editarIncluirContaUserControl.CancelButtonClick += (o, args) => { // When the CancelButtonClick event is raised, remove the second user control from the visual tree // and return to the first user control this.Content = null; }; // Show the second user control this.Content = editarIncluirContaUserControl; } - User
I have two user controls, all made in WPF C# application.The first one(called CevManualEmContaVinculadaUserControl) has a button called “Novo”.When I Click this button, I Open the another user control., called EditarIncluirContaUserControl.This another usercontrol has a button called “Cancelar”.When I click this button, I want to close this usercontrol and return to the first one.How to proceed?
- Assistant
You can implement the following steps to achieve this:
- In your first user control (CevManualEmContaVinculadaUserControl), handle the Click event of the "Novo" button:
private void NovoButton_Click(object sender, RoutedEventArgs e) { // Create an instance of the second user control var editarIncluirContaUserControl = new EditarIncluirContaUserControl(); // Hook up the CancelButtonClicked event so that we can handle it when the Cancel button is clicked editarIncluirContaUserControl.CancelButtonClicked += EditarIncluirContaUserControl_CancelButtonClicked; // Open the second user control this.Content = editarIncluirContaUserControl; } - User
I have two user controls, all made in WPF C# application.The first one(called CevManualEmContaVinculadaUserControl) has a button called “Novo” and a couple of labels and textboxes.When I Click this "Novo" button, I Open the another user control., called EditarIncluirContaUserControl.This another usercontrol has a button called “Cancelar”.When I click this button, I want to close this usercontrol and return to the first one, without lose those textboxes's data.
- Assistant