WPF之RadioButton的使用
<StackPanel Orientation="Vertical">
<RadioButton Content="RadioButon A" IsChecked="True"/>
<RadioButton Content="RadioButon B"/>
<RadioButton Content="RadioButon C"/>
<RadioButton Content="RadioButon D"/>
</StackPanel>
![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/b07ba542871e4f45b1c1bfd8531feb99.png)
2、常用属性介绍
Background:背景。
BorderBrush:边框颜色。
BorderThickness:边框宽度。
Content:获取或设置 ContentControl 的内容。
GroupName:控件所属组的组名。
FontFamily:获取或设置控件的字体系列。
FontSize:获取或设置字号。
FontStretch:获取或设置字体在屏幕上紧缩或加宽的程度。
FontStyle:获取或设置字体样式。
FontWeight:获取或设置指定字体的粗细。
Foreground:前景色。 Width/Height:宽度/高度。
IsEnabled:使能,是否可用。
IsChecked:获取或设置是否选中 ToggleButton,最重要的属性。
IsMouseOver:鼠标是否移入控件元素区域内。
IsPressed:是否按下。
Margin:元素外边距。
Name:元素标识名称。
Opacity:透明度。
Template:控件模板。
Visibility:可见性设置。
FlowDirection:获取或设置文本和其他用户界面 (UI) 元素在控制其布局的任何父元素内流动的方向。
RenderTransform:获取或设置影响此元素的呈现位置的转换信息。(旋转角度等设置)
RenderTransformOrigin:获取或设置由 RenderTransform 声明的任何可能呈现转换的中心点,相对于元素的边界。
HorizontalAlignment/VerticalAlignment:获取或设置在父元素(如面板或项控件)中组合此元素时所应用的水平对齐特征/垂直对齐特征。
HorizontalContentAlignment/VerticalContentAlignment:获取或设置控件内容的水平对齐方式/垂直对齐方式。
![在这里插入图片描述](https://i-blog.csdnimg.cn/direct/e90ff46ab0d64119ba0fc23b9f8aebd2.png)
<Window x:Class="WpfApp8.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfApp8"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<StackPanel Orientation="Vertical" Width="400">
<StackPanel Margin="20">
<RadioButton Name="rb1" Checked="CheckedFunc" Foreground="#dddddd" Margin="10" IsChecked="True">软触发</RadioButton>
<RadioButton Name="rb2" Checked="CheckedFunc" Foreground="#dddddd" Margin="10">硬触发</RadioButton>
<TextBlock Foreground="#dddddd" Margin="10" FontSize="15">
<Run >选中项为:</Run>
<Run x:Name="txtb"></Run>
</TextBlock>
</StackPanel>
</StackPanel>
</Grid>
</Window>
private void CheckedFunc(object sender, RoutedEventArgs e)
{
RadioButton radioButton = (sender as RadioButton);
if (radioButton != null && radioButton.Content != null)
{
txtb.Text = radioButton.Content.ToString();
}
}