Gridの子にGridを置き、その中で「group1」というGroupNameのRadioButtonを3つ設置しました。
group1の中でどのRadioButtonがチェックされているかを調べ、そのcontentを返すプログラムを作ろうと考えています。
XAML
1<Window 2 ~~ 3 > 4 <ScrollViewer> 5 <DockPanel> 6 <Grid> 7 <Grid 8 Grid.Column="0" 9 Grid.Row="3" 10 Grid.ColumnSpan="2"> 11 12 <Grid.ColumnDefinitions> 13 <ColumnDefinition 14 Width="Auto" /> 15 <ColumnDefinition 16 Width="Auto" /> 17 <ColumnDefinition 18 Width="Auto" /> 19 </Grid.ColumnDefinitions> 20 <RadioButton 21 Grid.Column="0" 22 Content="1" 23 Foreground="White" 24 FontSize="20" 25 GroupName="group1" /> 26 <RadioButton 27 Grid.Column="1" 28 Foreground="White" 29 FontSize="20" 30 Content="2" 31 GroupName="group1" /> 32 <RadioButton 33 Grid.Column="2" 34 Foreground="White" 35 FontSize="20" 36 Content="3" 37 GroupName="group1" /> 38 </Grid> 39 </Grid> 40 </DockPanel> 41 </ScrollViewer> 42</Window>
C#
1 public partial class Window1 : Window 2 { 3 public Window1() 4 { 5 InitializeComponent(); 6 } 7 8 private void CheckedRadiobuttonGroup1() 9 { 10 foreach (RadioButton rb in group1.Controls.OfType<RadioButton>()) { 11 if (rb.Checked) 12 { 13 Console.WriteLine("チェックされたのは" + rb.Text); 14 } 15 } 16 } 17 }
これを実行すると
group1は定義されていません
とエラーを吐いてしまいます
GridNameを使ってはどのRadioButtonがチェックされてるか調べられないのでしょうか?
ご教授願います。
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。