wpf WPF矩形绘制边框

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6782905/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 22:59:30  来源:igfitidea点击:

WPF Rectangle draw border

wpf

提问by

I need to draw dashed border in Grid Cell. I figured it out using Rectangle, but I need to show only rectangle's bottom border without left, right, or top !!

我需要在网格单元格中绘制虚线边框。我用 Rectangle 弄明白了,但我只需要显示矩形的底部边框,没有 left、right 或 top !

    Rectangle r = new Rectangle();
    r.StrokeThickness = 1;
    r.Stroke = Brushes.Black;
    r.StrokeDashArray = new DoubleCollection() { 5 };
    r.StrokeDashCap = PenLineCap.Flat;

Thanks!!

谢谢!!

采纳答案by CodeNaked

Looks like you can do it with a Rectangle, if you set the Height to 1 and then vertically align it to the bottom like so:

看起来你可以用一个矩形来做,如果你将高度设置为 1,然后像这样垂直对齐到底部:

<Rectangle Height="1" Stroke="Red" StrokeDashArray="1 2" VerticalAlignment="Bottom" />

回答by Arsen Khachaturyan

Go to Properties -> Brush -> Strokeand select the border-related information:

进入属性->画笔->描边,选择边框相关信息:

enter image description here

在此处输入图片说明

Also in the Properties -> Appearancesection you can do additional customizations over the border/stroke.

同样在“属性”->“外观”部分,您可以对边框/笔画进行其他自定义。