2015-10-22 71 views
0

我需要一些代碼的幫助少許。這個應該做的是找出用戶點擊的按鈕,然後根據用戶按下哪個按鈕來改變複選框。但是我不知道在var enabled = button.Name ==;這一行中放入if語句的內容。按鈕點擊複選框,根據if語句結果

 private void EnDis(object sender, RoutedEventArgs e) 
    { 
     var button = (Button)sender; 
     var enabled = button.Name == ; //confusing 
     var disabled = button.Name == ; //confusing 
     if(button.Name == "btnEnable_1") 
     { 
      chk_1.IsChecked = enabled; 
      chk_2.IsChecked = enabled; 
      chk_3.IsChecked = enabled; 
      chk_4.IsChecked = enabled; 
     } 
      if(button.Name == "btnDisable_1") 
     { 
      chk_1.IsChecked = disabled; 
      chk_2.IsChecked = disabled; 
      chk_3.IsChecked = disabled; 
      chk_4.IsChecked = disabled; 
     } 

     if(button.Name == "btnEnable_2") 
     { 
      chk_5.IsChecked = enabled; 
      chk_6.IsChecked = enabled; 
      chk_7.IsChecked = enabled; 
      chk_8.IsChecked = enabled; 
     } 

    } 

任何幫助或指導將非常感激!

回答

1

也許你想要這樣的東西?

private void EnDis(object sender, RoutedEventArgs e) 
{ 
    var button = (Button)sender; 
    if(button.Name == "btnEnable_1") 
    { 
     chk_1.IsChecked = true; 
     chk_2.IsChecked = true; 
     chk_3.IsChecked = true; 
     chk_4.IsChecked = true; 
    } 
     if(button.Name == "btnDisable_1") 
    { 
     chk_1.IsChecked = false; 
     chk_2.IsChecked = false; 
     chk_3.IsChecked = false; 
     chk_4.IsChecked = false; 
    } 

    if(button.Name == "btnEnable_2") 
    { 
     chk_5.IsChecked = true; 
     chk_6.IsChecked = true; 
     chk_7.IsChecked = true; 
     chk_8.IsChecked = true; 
    } 

} 
+0

非常感謝:) – Badja