精华内容
下载资源
问答
  • WPF RadioButton

    2020-12-12 11:40:11
    同属一个GroupName则互斥,只能选择一个 <StackPanel Orientation=...RadioButton GroupName="Group1" Content="苹果"></RadioButton> <RadioButton GroupName="Group1" Content="荔枝"></Ra

    同属一个GroupName则互斥,只能选择一个

    <StackPanel Orientation="Vertical">
        <Label Content="Group1:水果"></Label>
        <RadioButton GroupName="Group1" Content="苹果"></RadioButton>
        <RadioButton GroupName="Group1" Content="荔枝"></RadioButton>
        <RadioButton GroupName="Group1" Content="西瓜"></RadioButton>
        <RadioButton GroupName="Group1" Content="香蕉"></RadioButton>
        <Label Content="Group2:科目"></Label>
        <RadioButton GroupName="Group2" Content="语文"></RadioButton>
        <RadioButton GroupName="Group2" Content="数学"></RadioButton>
        <RadioButton GroupName="Group2" Content="英语"></RadioButton>
        <RadioButton GroupName="Group2" Content="物理"></RadioButton>
    </StackPanel>
    

    上面的示例中,可以选择水果、科目下各一个选项,所以水果和科目不互斥,水果之间互斥,科目之间互斥
    在这里插入图片描述

    示例代码

    RadioButton

    展开全文
  • wpf RadioButton效果

    2020-07-19 21:33:00
    Style x:Key="GroupSelectRadioButton_Left" TargetType="{x:Type RadioButton}"> <Setter Property="Background" Value="Transparent"/> <Setter Property="BorderBrush" Value="Transparent"/> ...
    <Style x:Key="GroupSelectRadioButton_Left" TargetType="{x:Type RadioButton}">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="BorderBrush" Value="Transparent"/>
            <Setter Property="Foreground" Value="Gray"></Setter>
            <Setter Property="Padding" Value="0"></Setter>
            <Setter Property="FontSize" Value="14"></Setter>
            <Setter Property="BorderThickness" Value="0"></Setter>
            <Setter Property="Height" Value="auto"></Setter>
            <Setter Property="SnapsToDevicePixels" Value="true"></Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type RadioButton}">
                        <Grid x:Name="grid"  VerticalAlignment="Stretch" HorizontalAlignment="Stretch"  ClipToBounds="True" >
                            <Rectangle x:Name="ButtonStock"  Fill="{TemplateBinding Background}" Stroke="Gray"  RadiusX="5" RadiusY="5" Margin="0,0,-5,0" StrokeThickness="1"/>
                            <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"  Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                        </Grid>
                      
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsChecked" Value="true">
                               
                                <Setter Property="Background" Value="Green"></Setter>
                                <Setter Property="Foreground" Value="White"></Setter>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="true">
                                <!--<Setter Property="Opacity" Value="0.6"></Setter>-->
    
                                <Setter Property="Background" Value="Green"></Setter>
                                <Setter Property="Foreground" Value="White"></Setter>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Opacity" Value="0.5" TargetName="grid" ></Setter>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    
        <Style x:Key="GroupSelectRadioButton_Middle" TargetType="{x:Type RadioButton}">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="BorderBrush" Value="Transparent"/>
            <Setter Property="Foreground" Value="Gray"></Setter>
            <Setter Property="Padding" Value="0"></Setter>
            <Setter Property="FontSize" Value="12"></Setter>
            <Setter Property="BorderThickness" Value="0"></Setter>
            <Setter Property="Height" Value="auto"></Setter>
            <Setter Property="SnapsToDevicePixels" Value="true"></Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type RadioButton}">
                        <Grid x:Name="grid"  VerticalAlignment="Stretch" HorizontalAlignment="Stretch"  ClipToBounds="True" >
                            <Rectangle x:Name="ButtonStock"  Fill="{TemplateBinding Background}" Stroke="Gray"  RadiusX="0" RadiusY="0" Margin="0,0,0,0" StrokeThickness="1"/>
                            <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"  Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                        </Grid>
                       
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsChecked" Value="true">
                               
                                <Setter Property="Background" Value="Gray"></Setter>
                                <Setter Property="Foreground" Value="White"></Setter>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="true">
                                <Setter Property="Opacity" Value="0.6"></Setter>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Opacity" Value="0.5" TargetName="grid" ></Setter>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
    
        <Style x:Key="GroupSelectRadioButton_Right" TargetType="{x:Type RadioButton}">
            <Setter Property="Background" Value="Transparent"/>
            <Setter Property="BorderBrush" Value="Transparent"/>
            <Setter Property="Foreground" Value="Gray"></Setter>
            <Setter Property="Padding" Value="0"></Setter>
            <Setter Property="FontSize" Value="14"></Setter>
            <Setter Property="BorderThickness" Value="0"></Setter>
            <Setter Property="Height" Value="auto"></Setter>
            <Setter Property="SnapsToDevicePixels" Value="true"></Setter>
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type RadioButton}">
                        <Grid x:Name="grid"  VerticalAlignment="Stretch" HorizontalAlignment="Stretch"  ClipToBounds="True" >
                            <Rectangle x:Name="ButtonStock"  Fill="{TemplateBinding Background}" Stroke="Gray"  RadiusX="5" RadiusY="5" Margin="-5,0,0,0" StrokeThickness="1"/>
                            <ContentPresenter VerticalAlignment="Center" HorizontalAlignment="Center"  Margin="{TemplateBinding Padding}" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                        </Grid>
                       
                        <ControlTemplate.Triggers>
                            <Trigger Property="IsChecked" Value="true">
                                
                                <Setter Property="Background" Value="Green"></Setter>
                                <Setter Property="Foreground" Value="White"></Setter>
                            </Trigger>
                            <Trigger Property="IsMouseOver" Value="true">
                                <!--<Setter Property="Opacity" Value="0.6"></Setter>-->
                                <Setter Property="Background" Value="Green"></Setter>
                                <Setter Property="Foreground" Value="White"></Setter>
                            </Trigger>
                            <Trigger Property="IsEnabled" Value="False">
                                <Setter Property="Opacity" Value="0.5" TargetName="grid" ></Setter>
                            </Trigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

     

     

    展开全文
  • WPF 自定义RadioButton样式 原文:WPF 自定义RadioButton样式一、RadioButton基本样式 RadioButton基本样式包含两种状态,这里也是使用两张图片来代替两种状态,当然你也可以通过IconFont或Path来替换...
    原文:WPF 自定义RadioButton样式

    一、RadioButton基本样式

    RadioButton基本样式包含两种状态,这里也是使用两张图片来代替两种状态,当然你也可以通过IconFont或Path来替换这两种状态。

    效果如下:

    样式代码如下:

    <Style x:Key="radBase" TargetType="RadioButton">
                <Setter Property="IsChecked" Value="False"/>
                <Setter Property="Background" Value="Transparent"/>
                <Setter Property="Foreground" Value="#555"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="RadioButton">
                            <DockPanel  Background="{TemplateBinding Background}" ToolTip="{TemplateBinding Content}" LastChildFill="False" Width="{TemplateBinding Width}">
                                <Image Margin="2 0 0 0" DockPanel.Dock="Left" x:Name="_img"  Stretch="None" Source="/Images/rdo_no.png"/>
                                <TextBlock DockPanel.Dock="Left" Margin="3 0 0 0" VerticalAlignment="Center" Foreground="{TemplateBinding Foreground}" Text="{TemplateBinding Content}" />
                            </DockPanel>
                            <ControlTemplate.Triggers>
                                <Trigger Property="IsChecked" Value="true">
                                    <Setter TargetName="_img" Property="Source" Value="/Images/rdo_yes.png"/>
                                </Trigger>
                            </ControlTemplate.Triggers>
                      </ControlTemplate>
                 </Setter.Value>
            </Setter>
     </Style>

    图片素材:

      

    二、RadioButton其它样式

    先看效果图:

    这种样式一般用于突出用户选择。这里的每个选项都是填充的颜色,你也可以选择填充文字内容。

    样式代码如下:

    <Style x:Key="RadioThemeColor" TargetType="RadioButton">
                <Setter Property="Margin" Value="1"/>
                <Setter Property="Background" Value="#e892ca"/>
                <Setter Property="Template">
                    <Setter.Value>
                        <ControlTemplate TargetType="RadioButton">
                            <Grid Background="{TemplateBinding Background}" Width="62" Height="35" Margin="{TemplateBinding Margin}">
                                <Border x:Name="_borderOver" Background="Transparent" BorderBrush="Transparent" BorderThickness="1" Margin="1">
    
                                </Border>
                                <Border x:Name="_borderChecked" Visibility="Collapsed" Background="#88000000" HorizontalAlignment="Right" VerticalAlignment="Bottom" Width="15" Height="15">
                                    <Path Data="M0,5 5,10 13,1" Margin="2 2 0 0" Stroke="White" StrokeThickness="1"/>
                                </Border>
                            </Grid>
                            <ControlTemplate.Triggers>
                                <Trigger Property="HasContent" Value="True">
                                    <Setter Property="FocusVisualStyle">
                                        <Setter.Value>
                                            <Style>
                                                <Setter Property="Control.Template">
                                                    <Setter.Value>
                                                        <ControlTemplate>
                                                            <Rectangle Margin="14,0,0,0" SnapsToDevicePixels="True" Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2"/>
                                                        </ControlTemplate>
                                                    </Setter.Value>
                                                </Setter>
                                            </Style>
                                        </Setter.Value>
                                    </Setter>
                                  
                                </Trigger>
                                <Trigger Property="IsMouseOver" Value="True">
                                    <Setter Property="BorderBrush" TargetName="_borderOver" Value="White"/>
                                </Trigger>
                                <Trigger Property="IsChecked" Value="True">
                                    <Setter Property="Visibility" TargetName="_borderChecked" Value="Visible"/>
                                </Trigger>
                           </ControlTemplate.Triggers>
                      </ControlTemplate>
                 </Setter.Value>
           </Setter>
     </Style>

    引用示例:

     <RadioButton Background="#e892ca"  Style="{StaticResource RadioThemeColor}"/>

     

    所有代码已经上传到github:https://github.com/cmfGit/WpfDemo.git

    posted on 2019-04-17 14:19 NET未来之路 阅读(...) 评论(...) 编辑 收藏

    转载于:https://www.cnblogs.com/lonelyxmas/p/10723262.html

    展开全文
  • WPF RadioButton 转换

    2015-05-04 18:09:00
    <RadioButton Content= " 小李 " GroupName= " SeatGroup " IsChecked= " {Binding people.name, Converter={StaticResource radioStringConverter}, ConverterParameter='小李'} " ></RadioButton> " Center...

    模型

    public class people
    {
       public string name{get;set;}       
       public bool? sex{get;set;}       
    }

    转换器

    namespace Helper
    {
        public class StringRadioConvert : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                if (value == null || parameter == null)
                    return false;
                string checkvalue = value.ToString();
                string targetvalue = parameter.ToString();
                bool r = checkvalue.Equals(targetvalue, StringComparison.InvariantCultureIgnoreCase);
                return r;
            }
    
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                if (value == null || parameter == null)
                    return null;
                bool usevalue = (bool)value;
                if (usevalue)
                    return parameter.ToString();
                return null;
            }
        }
        /// <summary>
        /// BOOL TO BOOL 
        /// </summary>
        public class BoolRadioConvert : IValueConverter
        {
            public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture)
            {
                if (value == null || parameter == null)
                    return false;
    
                bool flag = (bool)value;
    
    
                if ((flag && (string)parameter == "") || (!flag && (string)parameter == ""))
                {
                    return true;
                }
    
                return false;
            }
    
            public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
            {
                if (value == null || parameter == null)
                    return null;
                bool usevalue = (bool)value;
                if (!usevalue)
                    return null;
                Dictionary<string, bool> dict = new Dictionary<string, bool>();
                dict.Add("", true);
                dict.Add("", false);
    
                return dict[parameter.ToString()];
            }
        }
    
    }

    VIEW

    <UserControl ......
                 xmlns:helper="clr-namespace:Helper"......>
        <UserControl.Resources>
            <helper:StringRadioConvert x:Key="radioStringConverter" />
            <helper:BoolRadioConvert x:Key="radioBoolConverter" />
       </UserControl.Resources>
    <Label VerticalAlignment="Center" HorizontalAlignment="Right" FontWeight="ExtraBlack">用户:</Label> <RadioButton Content="小陈" GroupName="SeatGroup" IsChecked="{Binding people.name, Converter={StaticResource radioStringConverter}, ConverterParameter='小陈'}"></RadioButton> <RadioButton Content="小李" GroupName="SeatGroup" IsChecked="{Binding people.name, Converter={StaticResource radioStringConverter}, ConverterParameter='小李'}" ></RadioButton>
    <Label VerticalAlignment="Center" HorizontalAlignment="Right" FontWeight="ExtraBlack">输血史:</Label> <RadioButton Margin="4 0" GroupName="TransfusionGroup" IsChecked="{Binding people.sex , Converter={StaticResource radioBoolConverter}, ConverterParameter='男'}">男</RadioButton> <RadioButton Margin="4 0" GroupName="TransfusionGroup" IsChecked="{Binding people.sex , Converter={StaticResource radioBoolConverter}, ConverterParameter='女'}">女</RadioButton> </UserControl>

     

    解析:

    name为string类型,转化为bool

    sex需定义为bool?类型,否则会出现红框提示,此外,IsChecked是无法直接绑定变量的

     

    转载于:https://www.cnblogs.com/xcsn/p/4476890.html

    展开全文
  • WPF RadioButton MVVM模式

    2019-10-10 10:10:59
    xaml界面 ...RadioButton Content="个人提成" IsChecked="{Binding Path=objectType, Mode=TwoWay, Converter={StaticResource StatusConvert}, ConverterParameter=1}" Checked="ToggleButt...
  • WPF中单选框RadioButton

    2019-10-08 13:25:58
    单选框RadioButton的基本使用: <StackPanel Margin="10"> <Label FontWeight="Bold">Are you ready?</Label> <RadioButton>Yes</RadioButton> &...
  • wpf radiobutton模版设计成button样式

    热门讨论 2013-09-26 14:33:59
    wpf radiobutton模版设计成button样式
  • WPF 自定义RadioButton

    千次阅读 2015-01-01 22:21:32
    <RadioButton Content=" Filter" Focusable="False" Margin="307.333,59,0,0" VerticalAlignment="Top" Height="27.687" Style="{DynamicResource RadioButtonColorStyle}" HorizontalAlignment="Left"/> ...
  • WPFRadioButton使用

    千次阅读 2018-11-25 17:38:58
    WPFRadioButton使用界面展示代码展示设计界面后台属性说明 界面展示 代码展示 设计界面 &lt;!--单选框:中断任务or提前完成--&gt; &lt;RadioButton Name="RadComplete" Content="...
  • WPF RadioButton的绑定

    2019-01-14 15:57:00
    RadioButton Grid.Column ="0" Content ="仿真" VerticalAlignment ="Center" Margin ="10 5 0 5" IsChecked =" {Binding Path=SelectedDatabase.DataType, Converter={StaticResource EnumBoolConverter}...
  • RadioButton Content="boy"/> 2. 要使用分组,就是用 GroupName属性 <RadioButton Content="男" GroupName="sex"></RadioButton> <RadioButton Content="女" GroupName="sex"></...
  • WPF利用radiobutton制作菜单按钮 原文:WPF利用radiobutton制作菜单按钮 版权声明:欢迎转载。转载请注明出处,谢谢 https://blog.csdn...
  • WPFRadiobutton使用

    2013-12-19 11:19:00
    当界面上出现多组Radiobutton时,将所有的Radiobutton写在同一个Grid里面,导致系统认为所有的Radiobutton是同一组,造成选择混乱,解决的方法: 1.要为属于同个组的Radiobutton设置相同的GroupName,绑定同一个...
  • RadioButton x:Name="radioButton" Style="{StaticResource GroupSelectRadioButton_Left}" Content="周" Margin="0" > </RadioButton> <RadioButton x:Name="radioButton_Copy" Content="月" Grid....
  • WPF listbox内嵌radiobutton

    2020-11-25 11:13:26
    1.xaml中添加Windows.Resource <Window.Resources> <Style x:Key="radioButtonStyle" TargetType="{x:Type ListBox}"> <Setter Property="ItemContainerStyle"> ...Style Ta
  • RadioButton x:Name="radioButton" IsChecked="True" Content="界面" HorizontalAlignment="Left" Height="90" Margin="100,334,0,0" VerticalAlignment="Top" Width="60" Style="{DynamicResource ...
  • WPF RadioButton按钮控件取消选中设置 通常我们使用的RadioButton控件选中之后就不能进行取消选中的操作,我上网查找到了解决方法,如下: 首先我们在View视图这里写这个按钮的点击触发事件 然后来到后台,先声明一...
  • WPF绑定Radiobutton到enum

    2016-06-18 23:09:36
    WPF中经常会需要用到多个Radiobutton选择项,并且需要将选中的选项映射到某个枚举值enum中。这种情形的解决办法如下:1) 需要创建一个UserControl,举个例子代码如下:<UserControl x:Class="ShangfeiXApp....
  • WPF radiobutton实现传递复杂参数 为了实现对多种情况的处理 , 需要每一个radiobutton对应的是不同的情况 ,因此需要专递一个复杂的参数来实现想要的功能 要实现该功能 关键部分是绑定中的数据...
  • 关于WPF RadioButton和CheckBox绑定问题

    万次阅读 2017-08-31 14:21:46
    最近发现一个WPFRadioButton的奇怪现象,由于在网上也没搜到合适的答案,遂记录一下: 现象:当一个对象集合里,某些属性需要以RadioButton或者CheckBox的形式展现出来,并且会随着切换集合中的对象而变化时,...
  • 目的: RadioButton取消选中,两个RadioButton组合,如果其中一个已经被选中,再次点击则取消选中。...RadioButton只要单击,在执行点击事件之前IsChecked属性状态已经变成true,所以,不能通过判断Checked来设置C
  • 有一个需求,我们有很多条目,需要选择一个条目作为当前条目,这就需要用到单选,就需要在DataGrid中使用RadioButton, 我的数据中有一个字段为is_current, 为bool值,在RadioButton中,有一个IsChecked绑定是否选择...
  • WPFRadioButton的分组

    2013-12-23 21:03:00
    当界面上出现多组Radiobutton时,将所有的Radiobutton写在同一个Grid里面,导致系统认为所有的Radiobutton是同一组,造成选择混乱,解决的方法: 1.要为属于同个组的Radiobutton设置相同的GroupName,绑定同一个...

空空如也

空空如也

1 2 3 4 5 ... 16
收藏数 319
精华内容 127
关键字:

radiobuttonwpf