WPF Button pixelated on one site

时间:2015-08-11 11:05:22

标签: wpf xaml button

Every button with the following style is pixelated at the right site. You can see it clearly in the selected (blue) line:

enter image description here

这是导致问题的代码的一部分:

<Setter Property="Template">
  <Setter.Value>
    <ControlTemplate TargetType="Button">
      <Border>
        <Border.Background>
          <VisualBrush>
            <VisualBrush.Visual>
              <Grid Width="80" Height="20">
                <Grid.RowDefinitions>
                  <RowDefinition Height="2*"/>
                  <RowDefinition Height="*"/>
                </Grid.RowDefinitions>
                <Rectangle Grid.RowSpan="2" RadiusX="13" RadiusY="13">
                  <Rectangle.Fill>
                    <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                      <GradientStop Color="LightGray" Offset="0"/>
                      <GradientStop Color="Gray" Offset="1"/>
                    </LinearGradientBrush>
                  </Rectangle.Fill>
                </Rectangle>

                <Rectangle Margin="3,2" RadiusX="8" RadiusY="12">
                  <Rectangle.Fill>
                    <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                      <GradientStop Color="#dfff" Offset="0"/>
                      <GradientStop Color="#0fff" Offset="1"/>
                    </LinearGradientBrush>
                  </Rectangle.Fill>
                </Rectangle>

              </Grid>
            </VisualBrush.Visual>
          </VisualBrush>
        </Border.Background>
        <ContentPresenter 
          x:Name="contentPresenter"
          ContentTemplate="{TemplateBinding ContentTemplate}"
          Content="{TemplateBinding Content}"
          HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
          Margin="{TemplateBinding Padding}"
          VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
      </Border>
    </ControlTemplate>
  </Setter.Value>
</Setter>

有没有人知道为什么按钮在右边的网站上会像素化?

1 个答案:

答案 0 :(得分:3)

我认为问题不在你的Button风格中。这是你的风格在我的项目中的样子:

enter image description here

您的按钮可能是从其他模板继承样式的? (矩形,边框等)