8

そしてありがとうございました。

この質問は、この古い未回答の質問に非常によく似ています: 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>
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 を操作する必要があります。最後の 2 つの数値は画像の幅/高さである必要があります (画像が引き伸ばされているか、単に来ていないため、これを行う必要がありました)。右)。

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