2009-03-10 9 views

Trả lời

29

Bạn có thể tạo hiệu ứng gợn sóng bằng cách sử dụng những thay đổi sau đây để giải pháp Robert Macne của

Thêm một bàn chải trực quan để các Grid.Resources phần:

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

Và thay đổi bút để:

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

+1, đây chỉ là những gì tôi đã nghĩ đến nhưng không thể làm cho nó hoạt động chính xác, tốt đẹp! –

+0

Tôi tìm thấy một con đường bezier khối quy mô độc đáo khá khó khăn. Hai đường chéo hoạt động tốt, nhưng trông không tốt. – bstoney

+0

WavyBrush ở trên không phải là sóng mà tôi đã thử nghiệm. – Elisabeth

6

Một gạch dưới màu đỏ là đủ đơn giản:

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

Một lượn sóng gạch dưới màu đỏ sẽ tham gia nhiều hơn một chút, nhưng tôi nghĩ rằng bạn có thể tạo một VisualBrush với một điều lượn sóng màu đỏ trong nó, và thiết lập đó như Brush của Bút mà bạn chỉ định cho TextDecoration gạch dưới. Chỉnh sửa: xem bstoney bài đăng này.

+0

hi Robert, pls thấy WPF Câu hỏi của tôi, nó có thể hay không http://stackoverflow.com/questions/17541780/how-to-set-inline-images-vertically-center-in- richtextbox –

1

Tôi biết đây là một câu hỏi cũ nhưng tôi thích bàn chải này. Đó là một chút góc cạnh nhưng rất sạch sẽ.

<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

Đây là giải pháp @ bstoney được thực hiện bằng mã.

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