在WPF网格中绘制对角线 [英] Draw Diagonal Line in WPF Grid

查看:157
本文介绍了在WPF网格中绘制对角线的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我认为我正在尝试在WPF中做一些相对简单的事情,但不能在我的生活中弄清楚如何;并认为我可能处于过度复杂化的边缘。



如果我有一个3行3列的网格,并且我想加入两个单元格的拐角创建一个对角边框,这样做的最好方法是什么?



如果控件大小调整(如此绑定到边角)。

基本上我想在图中创建红线: Example Pic http://imm.io/7A4L

解决方案

您可以使用拉伸=填充的路径。对于你的例子中右上角的单元格,你可以使用:

 < Path Grid.Row =2Grid.Column =0Stroke =RedStrokeThickness =2Stretch =Fill> 
< Path.Data>
< LineGeometry StartPoint =0,0EndPoint =1,1/>
< /Path.Data>
< / Path>

填充拉伸使路径拉伸填充其父项,这给人的印象是坐标LineGeometry是相对的(X = 0,Y = 0是左上角,X = 1,Y = 1是右下角)。

I think I am trying to do something relatively simple in WPF, but can't for the life of me figure out how; and think I am probably on the verge of overcomplicating it.

If I had a grid which was 3 rows and 3 columns, and I wanted to join the corners of two cells to create a diagonal border, what would be the best way of doing so?

The lines should ideally re-size if the control is resized (so bound to the corners of the cell?).

Essentially I would like to create the red lines in the diagram hosted here: Example Pic http://imm.io/7A4L

解决方案

You could use a Path with Stretch=Fill. For the top right cell in your example, you would use:

<Path Grid.Row="2" Grid.Column="0" Stroke="Red" StrokeThickness="2" Stretch="Fill">
    <Path.Data>
        <LineGeometry StartPoint="0,0" EndPoint="1,1" />
    </Path.Data>
</Path>

The "Fill" stretch makes the Path stretch to fill its parent, which gives the impression that the coordinates of the LineGeometry are relative (X=0,Y=0 is top left, X=1,Y=1 is bottom right).

这篇关于在WPF网格中绘制对角线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆