2009-03-10 12 views
14

WPF में रेखांकित करता है, क्या FlowDocument तत्वों में वेवी अंडरलाइन (जैसे वर्तनी त्रुटियों की तरह) जोड़ने का कोई आसान तरीका है? Underline कक्षा है, लेकिन ऐसा लगता है कि इसे शैली देने का कोई तरीका नहीं है।Wavy FlowDocument

उत्तर

29

आप रॉबर्ट Macne के समाधान में निम्न परिवर्तन का उपयोग कर लहरदार प्रभाव बना सकते हैं

Grid.Resources अनुभाग के लिए एक दृश्य ब्रश करें:

<VisualBrush x:Key="WavyBrush" Viewbox="0,0,3,2" ViewboxUnits="Absolute" Viewport="0,0.8,6,4" ViewportUnits="Absolute" TileMode="Tile"> 
    <VisualBrush.Visual> 
     <Path Data="M 0,1 C 1,0 2,2 3,1" Stroke="Red" StrokeThickness="0.2" StrokeEndLineCap="Square" StrokeStartLineCap="Square" /> 
    </VisualBrush.Visual> 
</VisualBrush> 

और कलम बदलने के लिए:

<Pen Brush="{StaticResource WavyBrush}" Thickness="6" /> 
+0

+1, यह वही है जो मैं सोच रहा था लेकिन इसे सही तरीके से काम करने के लिए नहीं मिला, अच्छा! –

+0

मुझे अच्छी तरह से काफी मुश्किल पैमाने पर एक घन बेजियर पथ मिल रहा है। दो विकर्ण रेखाएं भी काम करती हैं, लेकिन अच्छी लगती नहीं थीं। – bstoney

+0

ऊपर WavyBrush एक लहर नहीं है जिसका मैंने परीक्षण किया था। – Elisabeth

6

एक लाल रेखांकन काफी सरल है:

<Grid xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
     xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> 
    <Grid.Resources> 
     <FlowDocument x:Key="doc"> 
      <Paragraph> 
       <Run Text="This text is underlined in red."> 
        <Run.TextDecorations> 
         <TextDecoration Location="Underline"> 
          <TextDecoration.Pen> 
           <Pen Brush="Red" Thickness="1" DashStyle="{x:Static DashStyles.Dot}"/> 
          </TextDecoration.Pen> 
         </TextDecoration> 
        </Run.TextDecorations> 
       </Run> 
      </Paragraph> 
     </FlowDocument> 
    </Grid.Resources> 
    <FlowDocumentReader Document="{StaticResource doc}"/> 
</Grid> 

एक लहरदार लाल रेखांकन थोड़ा और अधिक शामिल होगा, लेकिन मुझे लगता है कि आप इसे में एक लहरदार लाल बात के साथ एक VisualBrush बना सकते हैं, और सेट कि पेन के ब्रश के रूप में जिसे आप अंडरलाइनिंग टेक्स्टडिशन के लिए निर्दिष्ट करते हैं। संपादित करें: bstoney के लिए पोस्ट देखें।

+0

हाय रॉबर्ट, कृपया देख मेरी WPF प्रश्न, इसके संभावित या नहीं http://stackoverflow.com/questions/17541780/how-to-set-inline-images-vertically-center-in- richtextbox –

1

मुझे पता है कि यह एक पुराना सवाल है लेकिन मैं इस ब्रश को पसंद करता हूं। यह थोड़ा कोणीय है लेकिन बहुत साफ है।

<VisualBrush x:Key="WavyBrush"> 
     <VisualBrush.Visual> 
      <Path Data="M 0,2 L 2,0 4,2 6,0 8,2 10,0 12,2" Stroke="Red"/> 
     </VisualBrush.Visual> 
    </VisualBrush> 
4

यहां कोड में लागू @ bstoney का समाधान है।

Pen path_pen = new Pen(new SolidColorBrush(Colors.Red), 0.2); 
path_pen.EndLineCap = PenLineCap.Square; 
path_pen.StartLineCap = PenLineCap.Square; 

Point path_start = new Point(0, 1); 
BezierSegment path_segment = new BezierSegment(new Point(1, 0), new Point(2, 2), new Point(3, 1), true); 
PathFigure path_figure = new PathFigure(path_start, new PathSegment[] { path_segment }, false); 
PathGeometry path_geometry = new PathGeometry(new PathFigure[] { path_figure }); 

DrawingBrush squiggly_brush = new DrawingBrush(); 
squiggly_brush.Viewport = new Rect(0, 0, 6, 4); 
squiggly_brush.ViewportUnits = BrushMappingMode.Absolute; 
squiggly_brush.TileMode = TileMode.Tile; 
squiggly_brush.Drawing = new GeometryDrawing(null, path_pen, path_geometry); 

TextDecoration squiggly = new TextDecoration(); 
squiggly.Pen = new Pen(squiggly_brush, 6); 
text_box.TextDecorations.Add(squiggly); 
संबंधित मुद्दे