2013-07-22 98 views
13

我在一个可以与触摸一起使用的应用程序中有一些单选按钮。 因为最终用户可以有粗厚的手指,所以我想让圆圈和文字变得更大。调整单选按钮大小

问题是,我只能使文本更大,而不是单选按钮中的圆圈。

<RadioButton VerticalAlignment="Center" x:Name="rbtnContainers" Click="SetContainers" FontSize="18">Containers</RadioButton> 

使用高度也不起作用。它使得单选按钮更大,但圆圈保持不变。

任何提示或答案表示赞赏。

+0

在viewbox中使用它,并改变它的高度 – whoisthis

+0

+1为思考世界的厚厚的手指! –

回答

23

这应该适合你。

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

另一种选择是为RadioButton编写自己的ControlTemplate并根据需要更改其外观。

+0

工作正常,谢谢! –

+0

无论什么原因,当我申请,它扰乱了单选按钮的对齐 – Maslow

+0

非常好!它是一个快速简单的解决方案,而不是制作自定义模板 – t4taurus

2

若要仅调整圆圈大小,可以使用RadioButton模板并更改WidthHeightBulletChrome

<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

我得到 >命名空间“clr-namespace:Microsoft.Windows.Themes; assembly = PresentationFramework.Aero”中不存在名称“BulletChrome”。 – Maslow

+0

该项目需要引用'PresentationFramework.Aero'或任何定义'BulletChrome'的地方,如https://msdn.microsoft.com/en-us/library/microsoft.windows.themes.bulletchrome(v = vs.110)的.aspx – Maslow

0

一个多的黑客是尝试简单地改造对象,具有类似......

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

只要记住ScaleXScaleY需求相等,否则对象会看起来很尴尬

根据我自己的实验,这个渲染没有任何搞砸(例如没有对齐问题等)