WPF 按钮在一个站点上像素化

标签 wpf xaml button

具有以下样式的每个按钮都在正确的位置像素化。您可以在选定的(蓝色)行中清楚地看到它:

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>

有谁知道为什么按钮在正确的网站上像素化?

最佳答案

我认为问题不在于您的 Button风格。这是您在我的项目中的样式:

enter image description here

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

关于WPF 按钮在一个站点上像素化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31940067/

相关文章:

c# - 设置属性时从基类调用方法

c# - WPF 触发按钮可以在 ItemsControl 之外从 ItemsControl 执行

c# - ScrollTo 无法在 Xamarin.Forms 中使用分组的 ListView

android - 如何在按钮上调整文字?

wpf:获取组合框值

c# - 在 WPF/C# 中使用全局键盘钩子(Hook) (WH_KEYBOARD_LL)

wpf - XAML:DataTemplate 中的自定义绑定(bind)用于 GridViewColumn CellTemplate

c# - 使按钮宽度相同

C# - 如果字符串为空或有空格,则禁用按钮?

javascript - 从 Javascript 调用代码隐藏