2011-08-16 15 views
7

y gracias.Repita un cepillo de fondo en WPF

Esta pregunta es muy similar a esta vieja pregunta sin respuesta aquí: How to paint notebook-like lines as TextBox background? Sin embargo, no es lo mismo, no exactamente.

Me gustaría crear un bloc de notas con fondo de papel rayado, pero no estoy familiarizado con cómo repetir un pincel en XAML. ¿Cómo?

EDITAR

Aquí está la solución como parte de un cuadro de texto:

<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

En cuanto a la edición sugerido: Estoy de acuerdo, por favor extraer su solución concreta en una respuesta por separado. (Posiblemente también agregue una nota acerca de cómo 'LineHeight' y' LineStackingStrategy' resuelven el problema de alineación, si es necesario) –

Respuesta

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

¿Qué ajustaría para influir en el grosor de la línea? '' claramente no es correcto. Gracias. –

+0

@JerryNixon: En realidad debería ser el 'Pen.Thickness', posiblemente algunos problemas con aliasing si la línea no se vuelve más delgada para usted. –

0

Utilice un ImageBrush

<ImageBrush ImageSource="image.png" TileMode="Tile"/> 
+0

Esto es lo que tengo, pero solo muestra la imagen una vez, centrado. –

1

divertido, sólo estaba haciendo lo mismo. Aqui tienes. Probablemente tengas que jugar con TileMode para establecer la dirección del mosaico, y ViewPort; los dos últimos números deberían ser el ancho/alto de tu imagen (tuve que hacer esto porque mi imagen se estiraba o simplemente no venía) a la derecha).

<ImageBrush x:Key="WindowBackground" ImageSource="/Images/Background.png" TileMode="Tile" ViewportUnits="Absolute" Viewport="0,0,4,4" /> 
Cuestiones relacionadas