2016-04-05 29 views
0

ラジオボタンが4つあり、チェックがあるかどうかチェックしたいと思います。ラジオボタンがチェックされているかどうかを確認する方法

これは私のWPFのコードです:

<StackPanel Background="#FF3A3A49" Grid.Column="1" Grid.Row="4"> 
    <RadioButton x:Name="rtnRight" GroupName="answer" HorizontalAlignment="Center" VerticalAlignment="Top" Foreground="White" Content="value0" BorderBrush="White"/> 
    <RadioButton Content="value1" GroupName="answer" HorizontalAlignment="Center" VerticalAlignment="Center" Foreground="White" /> 
    <RadioButton Content="value2" GroupName="answer" HorizontalAlignment="Center" VerticalAlignment="Bottom" Foreground="White" /> 
    <RadioButton Content="value3" GroupName="answer" HorizontalAlignment="Center" VerticalAlignment="Bottom" Foreground="White" /> 
</StackPanel> 
<Button x:Name="btnNext" Grid.Column="1" Grid.Row="5" Content="Dalej" VerticalAlignment="Center" HorizontalAlignment="Center" Width="100" Height="50" Margin="0 0 0 0 " Foreground="#FFAC0303" BorderBrush="#FFC1C1C1" Background="#66FFFFFF" Click="btnNext_Click"></Button> 

私はbtnNextをクリックして、何のラジオボタンがチェックされていない後、私は、メッセージダイアログを表示したいです。これをどのようにコード化できますか?これは今までの私のbtnNext_Clickの機能です。

private async void btnNext_Click(object sender, RoutedEventArgs e) 
    {  
     if ("any radiobutton checked?") 
     { 
      await new Windows.UI.Popups.MessageDialog("Choose at least one answer").ShowAsync(); 
     } 
    } 

答えて

1

あなたのStackPanelの名前を指定してのように確認することができます。

<StackPanel Background="#FF3A3A49" Grid.Column="1" Grid.Row="4" x:Name="radioButtonStackPanel"> 
+0

感謝:ちょうどStackPanelのように名前を指定することを忘れないでください

if (!(radioButtonStackPanel.Children.OfType<RadioButton>().Any(rb => rb.IsChecked == true))) 

!できます。 "rb"と "rb.IsChecked"を使用するとどういう意味なのでしょうか?私は自分でタイプしようとしましたが、ビジュアルではrbと入力するとヒントが表示されませんでしたが、それは動作します:) – ktos1234

+0

ラムダ式です。[こちら](https:// msdn。 microsoft.com/en-CA/library/bb397687.aspx) – Habib

関連する問題