Sizing the radiobutton

前端 未结 3 1228
南旧
南旧 2021-01-04 00:46

I have some radiobuttons in an app that works with touch. Because the end-user can have thick fingers, I want to make the circle and text int he radiobutton bigger.

相关标签:
3条回答
  • 2021-01-04 01:00

    To resize only the circle, one can use RadioButton template and change Width and Height of BulletChrome.

    <ControlTemplate TargetType="RadioButton" x:Key="CustomRadioButtonStyle"
                         xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:s="clr-namespace:System;assembly=mscorlib" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mwt="clr-namespace:Microsoft.Windows.Themes;assembly=PresentationFramework.Aero">
    
            <BulletDecorator Background="#00FFFFFF">
                <BulletDecorator.Bullet>
                    <mwt:BulletChrome Height="25" Width="25" Background="{TemplateBinding Panel.Background}" BorderBrush="{TemplateBinding Border.BorderBrush}" RenderMouseOver="{TemplateBinding UIElement.IsMouseOver}" RenderPressed="{TemplateBinding ButtonBase.IsPressed}" IsChecked="{TemplateBinding ToggleButton.IsChecked}" IsRound="True"  />
                </BulletDecorator.Bullet>
                <ContentPresenter RecognizesAccessKey="True" Content="{TemplateBinding ContentControl.Content}" ContentTemplate="{TemplateBinding ContentControl.ContentTemplate}" ContentStringFormat="{TemplateBinding ContentControl.ContentStringFormat}" Margin="{TemplateBinding Control.Padding}" HorizontalAlignment="{TemplateBinding Control.HorizontalContentAlignment}" VerticalAlignment="{TemplateBinding Control.VerticalContentAlignment}" />
            </BulletDecorator>
    
            <ControlTemplate.Triggers>
    
                <Trigger Property="ContentControl.HasContent">
    
                    <Setter Property="FrameworkElement.FocusVisualStyle">
    
                        <Setter.Value>
    
                            <Style TargetType="IFrameworkInputElement">
    
                                <Style.Resources>
                                    <ResourceDictionary />
                                </Style.Resources>
    
                                <Setter Property="Control.Template">
    
                                    <Setter.Value>
    
                                        <ControlTemplate>
                                            <Rectangle Stroke="{DynamicResource {x:Static SystemColors.ControlTextBrushKey}}" StrokeThickness="1" StrokeDashArray="1 2" Margin="14,0,0,0" SnapsToDevicePixels="True" />
                                        </ControlTemplate>
                                    </Setter.Value>
                                </Setter>
                            </Style>
                        </Setter.Value>
                    </Setter>
    
                    <Setter Property="Control.Padding">
    
                        <Setter.Value>
                            <Thickness>4,0,0,0</Thickness>
                        </Setter.Value>
                    </Setter>
    
                    <Trigger.Value>
                        <s:Boolean>True</s:Boolean>
                    </Trigger.Value>
                </Trigger>
    
                <Trigger Property="UIElement.IsEnabled">
    
                    <Setter Property="TextElement.Foreground">
    
                        <Setter.Value>
                            <DynamicResource ResourceKey="{x:Static SystemColors.GrayTextBrushKey}" />
                        </Setter.Value>
                    </Setter>
    
                    <Trigger.Value>
                        <s:Boolean>False</s:Boolean>
                    </Trigger.Value>
                </Trigger>
            </ControlTemplate.Triggers>
        </ControlTemplate>
    
    0 讨论(0)
  • 2021-01-04 01:03

    A more of a hack would be to try to simply transform the object with something like...

    <RadioButton.RenderTransform>
        <CompositeTransform ScaleX="5" ScaleY="5"/>
    </RadioButton.RenderTransform>
    

    Just remember that ScaleX and ScaleY needs to be equal, otherwise the object will look stretched awkwardly

    According to my own experimenting, the rendering of this is not at all messed up (e.g. no alignment issues, etc.)

    0 讨论(0)
  • 2021-01-04 01:20

    This should work for you.

    <Viewbox Height="40">
         <RadioButton></RadioButton>
    </Viewbox>
    

    another alternative is to write your own ControlTemplate for the RadioButton and change its appearance as you want.

    0 讨论(0)
提交回复
热议问题