![](/img/trans.png)
[英]If statement to enable certain values based on button clicks C# and XAML
[英]Button clicks check boxes based on if statement results
我需要一些代碼的幫助。 這應該做的是找出用戶單擊的按鈕,然后根據用戶按下的按鈕來更改復選框。 但是我不知道在var enabled = button.Name ==;
放什么var enabled = button.Name ==;
從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;
}
}
任何幫助或指導將不勝感激!
也許您想要這樣的東西?
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;
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.