如何验证切换按钮状态?

时间:2015-01-03 09:15:12

标签: c# .net

我试图将本书Microsoft Visual Basic 2013 Step by Step的练习转换为Visual C#,但是在第206页上有一小段代码,我很难转换为C#。这里的任何人都可以帮我翻译这个if语句到C#?

If DisplayToggleBtn.IsChecked Then         
AutumnImage.Visibility = Windows.UI.Xaml.Visibility.Visible
Else
AutumnImage.Visibility = Windows.UI.Xaml.Visibility.Collapsed
End If

3 个答案:

答案 0 :(得分:0)

它应该更苗条

using Windows.UI.Xaml;

if (DisplayToggleBtn.IsChecked) {
    AutumnImage.Visibility  =  Visibility.Visible
else {
    AutumnImage.Visibility  =  Visibility.Collapsed
}

答案 1 :(得分:0)

试试这个:

using Windows.UI.Xaml;

if (DisplayToggleBtn.IsChecked.HasValue && DisplayToggleBtn.IsChecked.Value) {
    AutumnImage.Visibility  =  Visibility.Visible
else {
    AutumnImage.Visibility  =  Visibility.Collapsed
}

答案 2 :(得分:0)

更加苗条

AutumnImage.Visibility = DisplayToggleBtn.IsChecked ? 
                         Visibility.Visible : Visibility.Collapsed;