I have a button on a page (page1) in a WPF application. If I press that button on page1, how can I disable a button on Window1 ? Page 1 is shown in frame from Window1.
Thanks!
You need to create a delegate on page1
delegate void disabledButtonDelegate();
public disabledButtonDelegate disable button;
and access it on window1
var window= new Window1();
window.disabledButtonDelegate += DisableButton ; //or whatever method you call to disable it
window.Show();
The Control struture is: window1 button2 Page1 button1
You want to disable button2 in window1 when clicking button2 in page1.
In order to do that, you have some options:
In window1, add event handler to button1
if you use mvvm, you can send message when button1 is clicked in page1's code behind. then subscribe to this message in window1's code behind.
When Page1 is created, assign instance of button2 into page1. so Page1 knows button2. then it can disable button2 easily.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.