0
我已经在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>
拉伸=“填充”被设置为我需要能够重新调整大小的控件。必须有一种方法才能让图像顺利调整大小。 – user1145533 2012-02-03 15:09:48
@ user1145533您是否尝试将它放入“ViewBox”? – Rachel 2012-02-03 15:16:14
刚刚给了一个去,现在滴答看起来好多了,虽然由于某种原因,它现在比盒子大得多。任何想法为什么ViewBox如此之大?你是怎么得到这个复选框的默认值的? – user1145533 2012-02-03 15:52:35