2017-08-29 8 views
0

私はボタンレンダリングで奇妙な効果に直面しています。ボタンのエイリアシングレンダリング効果 - それを取り除く方法?

button image

ボタンのスタイルは、次の

<Style x:Key="DraggableItemDeleteButton" TargetType="{x:Type Button}"> 
    <Setter Property="Opacity" Value="1"/> 
    <Setter Property="VerticalAlignment" Value="Center"/> 
    <Setter Property="Background" Value="{StaticResource TransparentBrush}"/> 
    <Setter Property="BorderThickness" Value="1"/> 
    <Setter Property="BorderBrush" Value="{StaticResource TransparentBrush}"/> 
    <Setter Property="Width" Value="42"/> 
    <Setter Property="Height" Value="42"/> 
    <Setter Property="Command" Value="{Binding DataContext.DeleteItem, RelativeSource={RelativeSource AncestorType={x:Type UserControl}, Mode=FindAncestor}}"/> 
    <Setter Property="CommandParameter" Value="{Binding}"/> 
    <Setter Property="ToolTipService.InitialShowDelay" Value="500"/> 
    <Setter Property="ToolTipService.ShowDuration" Value="4500"/> 
    <Setter Property="ToolTipService.BetweenShowDelay" Value="1000"/> 
    <Setter Property="ToolTipService.Placement" Value="Top"/> 
    <Setter Property="Panel.ZIndex" Value="1"/> 
    <Setter Property="Template"> 
     <Setter.Value> 
      <ControlTemplate TargetType="{x:Type Button}"> 
       <Border Background="{TemplateBinding Background}" BorderThickness="{TemplateBinding BorderThickness}" BorderBrush="{TemplateBinding BorderBrush}"> 
        <ContentPresenter x:Name="contentPresenter" ContentTemplate="{TemplateBinding ContentTemplate}" Content="{TemplateBinding Content}" ContentStringFormat="{TemplateBinding ContentStringFormat}" Focusable="False" HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" Margin="{TemplateBinding Padding}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/> 
       </Border> 
      </ControlTemplate> 
     </Setter.Value> 
    </Setter> 
    <Style.Triggers> 
     <Trigger Property="Command" Value="{x:Null}"> 
      <Setter Property="Visibility" Value="Hidden"/> 
     </Trigger> 
     <Trigger Property="IsMouseOver" Value="True"> 
      <Setter Property="Background" Value="{StaticResource DeletingBrush}"/> 
      <Setter Property="BorderBrush" Value="{StaticResource DeletingBrush}"/> 
      <Setter Property="Opacity" Value="1"/> 
     </Trigger> 
     <DataTrigger Binding="{Binding IsMouseOver, RelativeSource={RelativeSource AncestorType={x:Type StackPanel}, Mode=FindAncestor}}" Value="True"> 
      <Setter Property="Opacity" Value="1"/> 
     </DataTrigger> 
    </Style.Triggers> 
    <Style.Resources> 
     <Style TargetType="{x:Type ToolTip}" BasedOn="{StaticResource TooltipStyleBase}"/> 
    </Style.Resources> 
</Style> 

である私は前BorderThickness="0"設定しようとしたが、結果は同じでした。 多分それは愚かな質問ですが、私は正しくそれをグーグルにする方法がわかりません。

+0

ボタンスタイルに ''を追加してみてください。 –

+0

ありがとう、それは動作します。テンプレート編集の前にwpfを深く学ぶべきです)) – GhfDllT

答えて

1

ボタンのスタイルにこれを追加してみてください:

<Setter Property="UseLayoutRounding" Value="True" /> 

WPFのレイアウトは、浮動小数点、整数ではないです。あなたが見ているのはanti-aliasingです。必要に応じて、SnapsToDevicePixels(レンダリングに影響する)とUseLayoutRounding(測定とレイアウトに影響を与えます)を使用して停止させることができます。残念ながら、私は2つの実用的な違いの詳細な説明を用意するつもりはありません。

1.私は「私には手がかりがありません」よりも良いと思った。

関連する問題