2012-03-10 36 views
0

我有功能滑塊:Button.Click事件

private void slider_change(object sender, RoutedPropertyChangedEventArgs<double> e) 
    { 
     if (e.NewValue < 2) 
     { 
      this.button1.Content = "A"; 
      this.button1.Click += aa; 
     } 
     if (e.NewValue < 6 && e.NewValue > 4) 
     { 
      this.button1.Content = "B"; 
      this.button1.Click += bb; 
     } 
     if (e.NewValue < 10 && e.NewValue > 8) 
     { 
      this.button1.Content = "C"; 
      this.button1.Click += cc; 
     } 
     if (e.NewValue < 4 && e.NewValue > 2) 
     { 
      this.button1.Content = "D"; 
      this.button1.Click += dd; 
     } 
     if (e.NewValue < 8 && e.NewValue > 6) 
     { 
      this.button1.Content = "E"; 
      this.button1.Click += ee; 
     } 
    } 

所以,我有一個按鈕,它5種不同的功能。如何刪除button1.click的以前處理程序?

回答

0

而不是根據滑塊值設置不同的處理程序,它可能會更容易鉤住一個單擊按鈕處理程序,然後根據滑塊的當前值更改該處理程序中發生的情況。這顯然會使訂閱和取消訂閱click事件變得更簡單,同時仍然允許您靈活地指定您的程序針對不同的滑塊值所做的操作。

0
this.button1.Click -= ee; 

這會從「EE」 - 函數

但我寧願方法dlev建議去參考。

相關問題