本文介绍了如何在WPF中实现虚线或虚线边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个ListViewItem,我正在将Style应用于它,我想在底部Border上放置一条虚线的灰线.

I have a ListViewItem that I am applying a Style to and I would like to put a dotted grey line as the bottom Border.

如何在WPF中执行此操作?我只能看到纯色笔刷.

How can I do this in WPF? I can only see solid color brushes.

推荐答案

这在我们的应用程序中效果很好,允许我们使用真实的Border,而不会与Rectangles混在一起:

This worked great in our application, allowing us to use a real Border and not mess around with Rectangles:

<Border BorderThickness="1,0,1,1">
   <Border.BorderBrush>
      <DrawingBrush Viewport="0,0,8,8" ViewportUnits="Absolute" TileMode="Tile">
         <DrawingBrush.Drawing>
            <DrawingGroup>
               <GeometryDrawing Brush="Black">
                  <GeometryDrawing.Geometry>
                     <GeometryGroup>
                        <RectangleGeometry Rect="0,0,50,50" />
                        <RectangleGeometry Rect="50,50,50,50" />
                     </GeometryGroup>
                  </GeometryDrawing.Geometry>
               </GeometryDrawing>
            </DrawingGroup>
         </DrawingBrush.Drawing>
      </DrawingBrush>
   </Border.BorderBrush>

   <TextBlock Text="Content Goes Here!" Margin="5"/>
</Border>

请注意,视口确定行中虚线的大小.在这种情况下,它将生成八个像素的虚线. Viewport ="0,0,4,4"将为您提供四个像素的虚线.

Note that the Viewport determines the size of the dashes in the lines. In this case, it generates eight-pixel dashes. Viewport="0,0,4,4" would give you four-pixel dashes.

这篇关于如何在WPF中实现虚线或虚线边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-17 22:29