2017-08-29 40 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(影響測量和佈局)來實現停止。不幸的是,我不準備提供兩個之間實際差異的詳細解釋。

1.我認爲聽起來比「我沒有線索」好。