WPF

2011-08-16 24 views
7

में पृष्ठभूमि ब्रश दोहराएं और धन्यवाद।WPF

यह प्रश्न इस पुराने, अनुत्तरित प्रश्न के समान है: How to paint notebook-like lines as TextBox background? हालांकि, यह वही नहीं है - बिल्कुल नहीं।

मैं एक नोटपैड, लाइन पेपर जैसी पृष्ठभूमि बनाना चाहता हूं लेकिन मैं 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> 
+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> 
+0

लाइन मोटाई को प्रभावित करने के लिए आप क्या समायोजित करेंगे? '<पेन मोटाई =" 5 "/>' स्पष्ट रूप से सही नहीं है। धन्यवाद। –

+0

@ जेरीनिक्सन: असल में यह 'पेन। हिकनेस' होना चाहिए, संभवतः एलियासिंग के साथ कुछ समस्याएं यदि लाइन आपके लिए पतली नहीं होती है। –

0

एक ImageBrush

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

यह मुझे मिला है, लेकिन यह केवल एक बार छवि को दिखा रहा है। –

1

अजीब बात है, सिर्फ एक ही बात कर रहा था का उपयोग करें:

संपादित

यहाँ किसी पाठ बॉक्स के हिस्से के रूप समाधान है। ये रहा। टाइलिंग की दिशा निर्धारित करने के लिए आपको शायद टाइलमोड के साथ खेलना होगा, और व्यूपोर्ट, आखिरी दो संख्याएं आपकी छवि की चौड़ाई/ऊंचाई होनी चाहिए (मुझे ऐसा करना था क्योंकि मेरी छवि को बढ़ाया जा रहा था या बस नहीं आ रहा था सही बाहर)।

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