2
我正在XAML中編寫畫筆,可以使用它來繪製Grid
的背景以創建橫幅。它看起來像這樣:防止在調整大小時在XAML Grid的背景中形變
An example of the brush applied to the background of a Grid http://i40.tinypic.com/8wl012.png
我想刷「拉伸」與Grid
當Window
調整大小,但我不想中心角變形。
The deformed background brush http://i39.tinypic.com/2nly98p.png
我只需要能夠繪製形狀的Grid
的背景。我怎樣才能避免變形?
我寫的代碼看起來是這樣的:
<Window x:Class="WpfApplication.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Height="60" Width="300">
<Window.Resources>
<DrawingBrush x:Key="GridBackground">
<DrawingBrush.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Geometry="M0,1 0,0 0.4,0 0.45,0.5 0.4,1Z" Brush="#FF6A00" />
<GeometryDrawing Geometry="M0.6,1 0.55,0.5 0.6,0 1,0 1,1Z" Brush="#FF0000" />
</DrawingGroup.Children>
</DrawingGroup>
</DrawingBrush.Drawing>
</DrawingBrush>
</Window.Resources>
<Grid Background="{StaticResource GridBackground}">
<TextBlock Foreground="White" VerticalAlignment="Center">Some text</TextBlock>
</Grid>
</Window>
形狀在網格的背景中很重要。我想對Grid本身做的唯一更改是添加Background屬性。 – 2009-06-23 02:18:20