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