N.D*_*N.D 2 .net c# wpf listbox radio-button
我需要在我的窗口上放置3个单选按钮,并让用户只选择一个按钮.我做了一个ListBox并设置了Selection mode = Single但我仍然可以选择所有这些,我需要将每个项目包装成某些东西......我不知道是什么以及如何.有人可以帮忙吗?也许有另一种方式来呈现单选按钮并只选择一个...?
这是xaml -
<ListBox SelectionMode="Single" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled" Background="Transparent" BorderThickness="0" Margin="0,0,0,57" HorizontalAlignment="Right" Width="304" Height="146" VerticalAlignment="Bottom">
<ListBoxItem>
<RadioButton Content="Option 1" Margin="0,0,0,10" Height="16" HorizontalAlignment="Left" Name="radioButton1" VerticalAlignment="Top" FontSize="12" />
</ListBoxItem>
<ListBoxItem>
<RadioButton Content="Option 2" Margin="0,0,0,10" Height="16" HorizontalAlignment="Left" Name="radioButton2" VerticalAlignment="Top" FontSize="12" />
</ListBoxItem>
<ListBoxItem>
<StackPanel Orientation="Horizontal" Height="90">
<RadioButton Content="Another : " Checked="radioButton4_Checked" Height="16" HorizontalAlignment="Left" Name="radioButton4" VerticalAlignment="Top" FontSize="12" />
<TextBox Width="225" Name="TextBox_AnotherReason" AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible"/>
</StackPanel>
</ListBoxItem>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
尝试使用RadioButton元素上的GroupName属性(请参阅http://arcanecode.com/2007/09/20/the-wpf-radiobutton/)!
<StackPanel>
<RadioButton GroupName=“One“ IsChecked=“True“>Option 1</RadioButton>
<RadioButton GroupName=“One“ IsChecked=“False“>Option 2</RadioButton>
<RadioButton GroupName=“Two“ IsChecked=“False“>Option 3</RadioButton>
<RadioButton GroupName=“Two“ IsChecked=“True“>Option 4</RadioButton>
</StackPanel>
Run Code Online (Sandbox Code Playgroud)
所以在你的情况下:
<ListBox SelectionMode="Single" ScrollViewer.HorizontalScrollBarVisibility="Disabled" ScrollViewer.VerticalScrollBarVisibility="Disabled" Background="Transparent" BorderThickness="0" Margin="0,0,0,57" HorizontalAlignment="Right" Width="304" Height="146" VerticalAlignment="Bottom">
<ListBoxItem>
<RadioButton GroupName=“Group1“ Content="Option 1" Margin="0,0,0,10" Height="16" HorizontalAlignment="Left" Name="radioButton1" VerticalAlignment="Top" FontSize="12" />
</ListBoxItem>
<ListBoxItem>
<RadioButton GroupName=“Group1“ Content="Option 2" Margin="0,0,0,10" Height="16" HorizontalAlignment="Left" Name="radioButton2" VerticalAlignment="Top" FontSize="12" />
</ListBoxItem>
<ListBoxItem>
<StackPanel Orientation="Horizontal" Height="90">
<RadioButton GroupName=“Group1“ Content="Another : " Checked="radioButton4_Checked" Height="16" HorizontalAlignment="Left" Name="radioButton4" VerticalAlignment="Top" FontSize="12" />
<TextBox Width="225" Name="TextBox_AnotherReason" AcceptsReturn="True" TextWrapping="Wrap" VerticalScrollBarVisibility="Visible"/>
</StackPanel>
</ListBoxItem>
</ListBox>
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
10597 次 |
| 最近记录: |