WPF之RadioButton的使用

WPF之RadioButton的使用

        <StackPanel Orientation="Vertical">
            <RadioButton Content="RadioButon A" IsChecked="True"/>
            <RadioButton Content="RadioButon B"/>
            <RadioButton Content="RadioButon C"/>
            <RadioButton Content="RadioButon D"/>
       
        </StackPanel>

在这里插入图片描述

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:获取或设置控件内容的水平对齐方式/垂直对齐方式。

在这里插入图片描述

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

        }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
要修改 WPF 中的 RadioButton,您可以使用样式和模板来自定义其外观。以下是一个简单的示例: ```xml <Window.Resources> <Style x:Key="CustomRadioButtonStyle" TargetType="{x:Type RadioButton}"> <Setter Property="Foreground" Value="Red"/> <Setter Property="Template"> <Setter.Value> <ControlTemplate TargetType="{x:Type RadioButton}"> <Grid> <Ellipse Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="2"/> <Ellipse x:Name="InnerEllipse" Margin="8" Fill="{TemplateBinding Foreground}" Visibility="Collapsed"/> </Grid> <ControlTemplate.Triggers> <Trigger Property="IsChecked" Value="True"> <Setter TargetName="InnerEllipse" Property="Visibility" Value="Visible"/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </Window.Resources> <Grid> <StackPanel> <RadioButton Content="Option 1" Style="{StaticResource CustomRadioButtonStyle}"/> <RadioButton Content="Option 2" Style="{StaticResource CustomRadioButtonStyle}"/> <RadioButton Content="Option 3" Style="{StaticResource CustomRadioButtonStyle}"/> </StackPanel> </Grid> ``` 在这个示例中,我们使用一个样式来定义 RadioButton 的外观。它包含一个控件模板,在其中我们使用两个椭圆形组成 RadioButton 的外观。第一个椭圆形是 RadioButton 的背景,第二个椭圆形是 RadioButton 的选中状态指示器。我们使用一个触发器来控制选中状态指示器的可见性。 您可以通过调整样式和模板来自定义 RadioButton 的外观,以满足您的需求。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值