重复在WPF背景刷 [英] Repeat a background brush in WPF

查看:169
本文介绍了重复在WPF背景刷的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

和谢谢你。

这问题很相似,这个古老的,悬而未决的问题在这里:
<一href=\"http://stackoverflow.com/questions/4041642/wpf-how-to-paint-notebook-like-lines-as-textbox-background\">How ?油漆笔记本状线作为文本框背景的然而,这是不一样的。 - 不完全

我想创建一个记事本,横格纸般的背景,但我不是不熟悉如何在XAML重复刷。你怎么了?

修改

下面是解决方案作为一个TextBox的一部分:

 &LT;文本框TextBlock.LineHeight =20
         TextBlock.LineStackingStrategy =BlockLineHeight
         填充=20,10,20,20TextWrapping =自动换行&GT;
  &LT; TextBox.Background&GT;
    &LT; D​​rawingBrush TILEMODE =平​​铺拉伸=无视=0,0,20,20
                  ViewportUnits =绝对不透明度=&GT07。
      &LT; D​​rawingBrush.Drawing&GT;
          &LT; GeometryDrawing&GT;
              &LT; GeometryDrawing.Pen&GT;
                  &LT;笔刷=红深蓝/&GT;
              &LT; /GeometryDrawing.Pen>
              &LT; GeometryDrawing.Geometry&GT;
                  &LT; LineGeometry StartPoint可以=0,0终点=20.0/&GT;
              &LT; /GeometryDrawing.Geometry>
          &LT; / GeometryDrawing&GT;
      &LT; /DrawingBrush.Drawing>
    &LT; / DrawingBrush&GT;
  &LT; /TextBox.Background>
  现在是时候让所有的好男人来到他们的国家的援助。
  现在是时候让所有的好男人来到他们的国家的援助。
  现在是时候让所有的好男人来到他们的国家的援助。
  现在是时候让所有的好男人来到他们的国家的援助。
  现在是时候让所有的好男人来到他们的国家的援助。
&LT; /文本框&GT;


解决方案

 &LT; D​​rawingBrush TILEMODE =平​​铺拉伸=无
              视=0,0,20,20ViewportUnits =绝对&GT;
    &LT; D​​rawingBrush.Drawing&GT;
        &LT; GeometryDrawing&GT;
            &LT; GeometryDrawing.Pen&GT;
                &LT;笔刷=灰色/&GT;
            &LT; /GeometryDrawing.Pen>
            &LT; GeometryDrawing.Geometry&GT;
                &LT; LineGeometry StartPoint可以=0,0
                              终点=20.0/&GT;
            &LT; /GeometryDrawing.Geometry>
        &LT; / GeometryDrawing&GT;
    &LT; /DrawingBrush.Drawing>
&LT; / DrawingBrush&GT;

and thank you.

This question is very similar to this old, unanswered question here: How to paint notebook-like lines as TextBox background? However, it is not the same - not exactly.

I would like to create a notepad, lined paper-like background but I am not not familiar with how to repeat a brush in XAML. How do you?

EDIT

Here's the solution as part of a 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>

解决方案

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

这篇关于重复在WPF背景刷的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆