8

谢谢。

这个问题与这里的这个古老的、未回答的问题非常相似: 如何将类似笔记本的线条绘制为文本框背景?然而,它不一样——不完全一样。

我想创建一个记事本,衬纸般的背景,但我不熟悉如何在 XAML 中重复画笔。你怎么?

编辑

这是作为文本框一部分的解决方案:

<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>
4

3 回答 3

10
<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>
于 2011-08-16T20:49:28.737 回答
2

有趣的是,只是在做同样的事情。给你。您可能必须使用 TileMode 来设置平铺的方向,以及 ViewPort,最后两个数字应该是图像的宽度/高度(我必须这样做,因为我的图像被拉伸或只是没有出现正确)。

<ImageBrush x:Key="WindowBackground" ImageSource="/Images/Background.png" TileMode="Tile" ViewportUnits="Absolute" Viewport="0,0,4,4" />
于 2011-08-16T18:39:30.083 回答
0

使用 ImageBrush

<ImageBrush ImageSource="image.png" TileMode="Tile"/>
于 2011-08-16T18:38:02.597 回答