我的Window.xaml上有几个按钮, 有趣的是,当我运行应用程序时,即使我为每个应用程序使用相同的代码,它们也会有所不同。
这是截图:
可以注意到它们的边框看起来不一样(特别是在Y按钮上)..
以下是我的每个自定义按钮的代码:(X,Y和Z)
<Button x:Name="btnX"
Grid.Column="1"
FontSize="15"
BorderThickness="1"
Content="X"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Foreground="Black"
Background="#d3d3d3"
BorderBrush="Black" Margin="5">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Border BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}"
Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Border>
</ControlTemplate>
</Button.Template>
</Button>
<Button x:Name="btnZ"
Grid.Column="2"
FontSize="15"
Content="Z"
BorderThickness="1"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Foreground="Black"
Background="#d3d3d3"
BorderBrush="Black" Margin="5">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Border BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}"
Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Border>
</ControlTemplate>
</Button.Template>
</Button>
<Button x:Name="btnY"
Grid.Column="2"
Grid.Row="1"
FontSize="15"
Content="Y"
BorderThickness="1"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Foreground="Black"
Background="#d3d3d3"
BorderBrush="Black" Margin="5">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Border BorderThickness="{TemplateBinding BorderThickness}"
BorderBrush="{TemplateBinding BorderBrush}"
Background="{TemplateBinding Background}">
<ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
VerticalAlignment="{TemplateBinding VerticalContentAlignment}" />
</Border>
</ControlTemplate>
</Button.Template>
</Button>