AspBucket offers ASP.NET, C#, VB, Jquery, CSS, Ajax, SQL tutorials. It is the best place for programmers to learn

Thursday, 5 January 2017

How to create a custom style for Radio button in WPF?

In this article I am going to explain how to create a custom styling for wpf radio-button. We can modify the radio-button according to our custom requirement.  Please check below code for modifying the template & creating custom radio-button in WPF.

    <Image Source="selected.png" x:Key="RadioButtonOn" Width="18" Height="18"/>
    <Image Source="unselected.png" x:Key="RadioButtonOff" Width="18" Height="18"/>
    
    <Style TargetType="RadioButton" x:Key="myCustomRadioButton">
        <Setter Property="FontFamily" Value="Segoe UI semibold"/>
        <Setter Property="FontSize" Value="13"/>
        <Setter Property="Foreground" Value="#94979b"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type RadioButton}">
                    <Grid>
                        <Image Source="unselected.png" Width="18" Height="18"/>
                        <ContentPresenter/>
                    </Grid>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="IsChecked" Value="True">
                <Setter Property="Content" Value="{DynamicResource RadioButtonOn}"/>
            </Trigger>
            <Trigger Property="IsChecked" Value="False">
                <Setter Property="Content" Value="{DynamicResource RadioButtonOff}"/>
            </Trigger>
        </Style.Triggers>
    </Style>

0 comments :

Post a Comment

  • Popular Posts
  • Comments