简体   繁体   English

WPF vb.net中窗口上的页面禁用按钮

[英]Button on page disable button on Window in WPF vb.net

I have a button on a page (page1) in a WPF application. 我在WPF应用程序的页面(第1页)上有一个按钮。 If I press that button on page1, how can I disable a button on Window1 ? 如果按第1页上的按钮,如何禁用Window1上的按钮? Page 1 is shown in frame from Window1. 页面1显示在Window1的框架中。

Thanks! 谢谢!

You need to create a delegate on page1 您需要在第1页上创建一个委托

delegate void disabledButtonDelegate();

public disabledButtonDelegate disable button;

and access it on window1 并在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 控制结构是:window1 button2 Page1 button1

You want to disable button2 in window1 when clicking button2 in page1. 您要在单击页面1中的button2时禁用window1中的button2。

In order to do that, you have some options: 为此,您有一些选择:

  1. In window1, add event handler to button1 在window1中,将事件处理程序添加到button1

  2. if you use mvvm, you can send message when button1 is clicked in page1's code behind. 如果使用mvvm,则可以在后面的page1代码中单击button1时发送消息。 then subscribe to this message in window1's code behind. 然后在window1的代码后面订阅此消息。

  3. When Page1 is created, assign instance of button2 into page1. 创建Page1后,将button2的实例分配给page1。 so Page1 knows button2. 因此Page1知道button2。 then it can disable button2 easily. 然后可以轻松禁用button2。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM