我試圖在按鈕周圍繪製虛線邊框,但是不顯示邊框。不知道我在這裏做錯了什麼,你能幫忙嗎?按鈕周圍的虛線邊框
我的XAML代碼:
<Page xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="300" Width="300">
<Grid Background="Ivory">
<Border Width="101" Height="31">
<Border.BorderBrush>
<VisualBrush>
<VisualBrush.Visual>
<Rectangle StrokeThickness="1" Stroke="Red" StrokeDashArray="1 2"/>
</VisualBrush.Visual>
</VisualBrush>
</Border.BorderBrush>
<Button Width="100" Height="30">
Focus Here</Button>
</Border>
</Grid>
</Page>
注意:眼前的問題是有邊框的厚度,但仍即使加入了borderThickness之後,虛線邊框沒有出現。
難道你還需要設置'BorderThickness'爲大於0? 'StrokeThickness'是畫筆筆觸,邊框上的BorderThickness決定了知名度,據我所知 – Charleh 2013-02-18 12:12:49
我還沒有看到過像這樣的虛線邊框 - 你是否嘗試將'Rectangle'尺寸設置爲與邊框相同。可能與矩形大小有關? – Charleh 2013-02-18 12:17:55
是的,這是問題 - 我認爲邊界實際上在做的是爲自己的每個「邊緣」渲染一個畫筆,基本上渲染4個矩形。如果你設置的大小矩形都是正確的大小,但基於其原點正確居中,所以看起來很好。獲得虛線邊界可能有更好的方法... – Charleh 2013-02-18 12:24:29