谢谢你。
这个问题与这个古老的,未解决的问题非常类似: How to paint notebook-like lines as TextBox background?但是,它不完全相同 - 不完全是。
我想创建一个记事本,衬里纸张般的背景,但我不熟悉如何在XAML中重复画笔。你好吗?
修改
以下是作为TextBox一部分的解决方案:
<TextBox TextBlock.LineHeight="20"
TextBlock.LineStackingStrategy="BlockLineHeight"
Padding="20,10,20,20" TextWrapping="Wrap">
<TextBox.Background>
<DrawingBrush TileMode="Tile" Stretch="None" Viewport="0,0,20,20"
ViewportUnits="Absolute" Opacity=".07">
<DrawingBrush.Drawing>
<GeometryDrawing>
<GeometryDrawing.Pen>
<Pen Brush="RoyalBlue" />
</GeometryDrawing.Pen>
<GeometryDrawing.Geometry>
<LineGeometry StartPoint="0,0" EndPoint="20,0"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
</TextBox.Background>
Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.
Now is the time for all good men to come to the aid of their country.
</TextBox>
答案 0 :(得分:9)
<DrawingBrush TileMode="Tile" Stretch="None"
Viewport="0,0,20,20" ViewportUnits="Absolute">
<DrawingBrush.Drawing>
<GeometryDrawing>
<GeometryDrawing.Pen>
<Pen Brush="Gray"/>
</GeometryDrawing.Pen>
<GeometryDrawing.Geometry>
<LineGeometry StartPoint="0,0"
EndPoint="20,0"/>
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingBrush.Drawing>
</DrawingBrush>
答案 1 :(得分:1)
好笑,只是在做同样的事情。你去吧。您可能需要使用TileMode来设置平铺的方向,而ViewPort,最后两个数字应该是图像的宽度/高度(我必须这样做,因为我的图像被拉伸或者没有来在右边)。
<ImageBrush x:Key="WindowBackground" ImageSource="/Images/Background.png" TileMode="Tile" ViewportUnits="Absolute" Viewport="0,0,4,4" />
答案 2 :(得分:0)
使用ImageBrush
<ImageBrush ImageSource="image.png" TileMode="Tile"/>