我試圖設計一個WPF按鈕,使其具有圓角和黑色邊框。繼多個例子在網上,我想出了以下樣式:WPF按鈕造型時無法移除奇怪的「邊框」
<Style x:Key="MyBlackButton" TargetType="{x:Type Button}">
<Setter Property="Background" Value="#FF282828"/>
<Setter Property="Foreground" Value="White"/>
<Setter Property="FontSize" Value="16"/>
<Setter Property="FontWeight" Value="Bold"/>
<Setter Property="Height" Value="40"/>
<Setter Property="OverridesDefaultStyle" Value="true" />
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Button}">
<Grid x:Name="ButtonGrid">
<Border CornerRadius="5" BorderBrush="Black" BorderThickness="1" Background="{TemplateBinding Background}">
<Grid Margin="10,0,10,2">
<ContentPresenter HorizontalAlignment="Center" VerticalAlignment="Center" Margin="0"/>
</Grid>
</Border>
</Grid>
</ControlTemplate>
</Setter.Value>
</Setter>
</Style>
<Button Content="My button" Style="{StaticResource MyBlackButton}" />
這幾乎看起來不錯,但不是在按鈕的頂部和底部顯示正確的邊界,你可以從下面的變焦上看到實際的按鈕:
要嘗試找出我增加了一個更厚的邊框,看看是否有任何變化的問題。正如你可以在下圖中看到有一種「邊框」按鈕裏面的:
用細邊框所以,邊框看起來在按鈕的頂部和底部的模糊,並與一個很厚的邊框可以看到內邊框(我猜在薄邊框的頂部可以看到它,看起來很模糊)。
這是怎麼回事?爲什麼我無法在按鈕周圍找到漂亮的邊框?
'UseLayoutRounding = 「真」''&& SnapsToDevicePixels = 「真」' – dymanoid
添加這兩個屬性到風格(作爲setter)的幫助相當多,但不完全。看看這張圖片,你可以看到上邊框仍然不是一條黑線:http://i.imgur.com/KdoMMur.png – GTHvidsten