复选框路径别名

时间:2012-02-03 13:47:32

标签: wpf xaml checkbox

我在WPF中创建了一个复选框,但它看起来非常难看,框中的刻度非常粗糙。我试图将RenderOptions.EdgeMode设置为别名,但是没有修复它,我错过了什么?

代码如下:

<Style x:Key="{x:Type CheckBox}" TargetType="CheckBox">
        <Setter Property="SnapsToDevicePixels" Value="true"/>
        <Setter Property="OverridesDefaultStyle" Value="true"/>
        <Setter Property="FocusVisualStyle" Value="{DynamicResource CheckBoxFocusVisual}" />        
        <Setter Property="Foreground" Value="{StaticResource FGBrush}"/>
        <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
        <Setter Property="VerticalContentAlignment" Value="Stretch"/>
        <Setter Property="RenderOptions.EdgeMode" Value="Aliased"/>        
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="CheckBox">
                    <BulletDecorator Background="Transparent">
                        <BulletDecorator.Bullet>
                            <Grid Width="12" Height="12" MinHeight="{DynamicResource ResourceKey=MinimumIteractSizeDips}"
                                        MinWidth="{DynamicResource ResourceKey=MinimumIteractSizeDips}" 
                                  SnapsToDevicePixels="True" RenderOptions.EdgeMode="Aliased">

                                <Border x:Name="Border" 
                                        BitmapEffect="{StaticResource DropShadow}"
                                        MinHeight="{DynamicResource ResourceKey=MinimumIteractSizeDips}"
                                        MinWidth="{DynamicResource ResourceKey=MinimumIteractSizeDips}"
                                        CornerRadius="0" 
                                        Background="{StaticResource GreyGradientBrush}"
                                        BorderThickness="1"
                                        BorderBrush="{StaticResource NormalBorderBrush}" RenderOptions.EdgeMode="Aliased">

                                    <!--<Path Stretch="Fill"
                                              Margin="3"
                                                x:Name="CheckMark"
                                    SnapsToDevicePixels="False" 
                                    Stroke="{StaticResource GlyphBrush}"
                                    StrokeThickness="3"
                                    Fill="{DynamicResource GlyphBrush}"
                                          RenderOptions.EdgeMode="Aliased"
                                    Data="M103.78572,598.96112 L105.09846,597.5661 L107.00806,600.16229 C107.00806,600.16229 109.91004,592.74463 109.91004,592.74463 C109.91004,592.74463 111.74678,593.79761 111.74678,593.79761 C111.74678,593.79761 107.88566,602.75848 107.88566,602.75848 L106.60118,602.75848 z" />-->


                                    <Path Stretch="Fill"
                                              Margin="3"
                                                x:Name="CheckMark"
                                    SnapsToDevicePixels="False" 
                                    Stroke="{StaticResource GlyphBrush}"
                                    StrokeThickness="3"
                                    Fill="{DynamicResource GlyphBrush}"
                                          RenderOptions.EdgeMode="Aliased"
                                    Data="M103.78572,598.96112 L105.09846,597.5661 L107.00806,600.16229 C107.00806,600.16229 109.91004,592.74463 109.91004,592.74463 C109.91004,592.74463 111.74678,593.79761 111.74678,593.79761 C111.74678,593.79761 107.88566,602.75848 107.88566,602.75848 L106.60118,602.75848 z" />

                                </Border>
                            </Grid>
                        </BulletDecorator.Bullet>
                        <ContentPresenter Margin="4,0,0,0"
                                VerticalAlignment="Center"
                                HorizontalAlignment="Left"
                                RecognizesAccessKey="True"/>
                    </BulletDecorator>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="false">
                            <Setter TargetName="CheckMark" Property="Visibility" Value="Collapsed"/>
                        </Trigger>
                        <!--<Trigger Property="IsChecked" Value="{x:Null}">
                            <Setter TargetName="CheckMark" Property="Data" Value="M 0 7 L 7 0" />
                        </Trigger>-->
                        <Trigger Property="IsMouseOver" Value="true">
                            <Trigger.EnterActions>
                                <BeginStoryboard Name="HighlightAnim">
                                    <Storyboard TargetName="Border" TargetProperty="Opacity" >
                                        <DoubleAnimation To="0.5" Duration="00:00:00.1"/>
                                    </Storyboard>
                                </BeginStoryboard>
                            </Trigger.EnterActions>
                            <Trigger.ExitActions>
                                <StopStoryboard BeginStoryboardName="HighlightAnim"/>
                            </Trigger.ExitActions>
                        </Trigger>
                        <Trigger Property="IsPressed" Value="true">
                            <Setter TargetName="Border" Property="Background" Value="{StaticResource PressedBrush}" />
                            <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource PressedBorderBrush}" />
                        </Trigger>
                        <Trigger Property="IsEnabled" Value="false">
                            <Setter TargetName="Border" Property="Background" Value="{StaticResource DisabledBackgroundBrush}" />
                            <Setter TargetName="Border" Property="BorderBrush" Value="{StaticResource DisabledBorderBrush}" />
                            <Setter Property="Foreground" Value="{StaticResource DisabledForegroundBrush}"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>

1 个答案:

答案 0 :(得分:0)

如果我不得不猜测我会说它与Path对象中的所有小数有关,或者可能是Stretch=Fill

这是默认的CheckBox Path

<Path Visibility="Collapsed"
      Width="7"
      Height="7"
      x:Name="CheckMark"
      SnapsToDevicePixels="False"
      StrokeThickness="2"
      Data="M 0 0 L 7 7 M 0 7 L 7 0">
      <Path.Stroke>
           <SolidColorBrush Color="{DynamicResource GlyphColor}" />
      </Path.Stroke>
 </Path>

这是你的Path

<Path Stretch="Fill"
      Margin="3"
      x:Name="CheckMark"
      SnapsToDevicePixels="False" 
      Stroke="{StaticResource GlyphBrush}"
      StrokeThickness="3"
      Fill="{DynamicResource GlyphBrush}"
      RenderOptions.EdgeMode="Aliased"
      Data="M103.78572,598.96112 L105.09846,597.5661 L107.00806,600.16229 C107.00806,600.16229 109.91004,592.74463 109.91004,592.74463 C109.91004,592.74463 111.74678,593.79761 111.74678,593.79761 C111.74678,593.79761 107.88566,602.75848 107.88566,602.75848 L106.60118,602.75848 z" />

我建议一次更改一个属性,将您的版本更改为MSDN版本,并查看哪个修复了该问题。我猜它是Path.Data,但也可能是其他属性之一。