[英]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.