2016-04-05 32 views
0

4 radyo düğmesi var ve herhangi bir kontrol olup olmadığını kontrol etmek istiyorum.Herhangi bir radyo düğmesi kontrol edilirse nasıl kontrol edilir

Bu benim WPF kodudur: Bir mesaj iletişim göstermek istiyorum, ben btnNext tıklayın ve hiçbir radiobuttons kontrol edildikten sonra

<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> 

. Bunu nasıl kodlayabilirim? Bu benim şimdiye kadar btnNext_Click işlevim.

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(); 
     } 
    } 

cevap

1

Sen gibi kontrol ardından StackPanel için bir ad belirtin ve edebilirsiniz:

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

Tıpkı StackPanel için bir ad belirtin unutmayın:

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

teşekkür! İşe yarıyor. Sadece "rb" ve sonra "rb.IsChecked" kullandığınızda ne anlama geliyor? Ben kendim yazmayı denedim ve görsel rb yazarken bana herhangi bir ipucu göstermedi ... ama işe yaradı :) – ktos1234

+0

Bu lambda ifadesidir, onlar hakkında daha fazla bilgi edinebilirsiniz [burada] (https: // msdn. microsoft.com/en-CA/library/bb397687.aspx) – Habib

İlgili konular