[英]WPF: Drawing shapes in ListView
I have a list of lines with attributes such as Brush, line thickness, etc. and I have a custom legend, which is a GridView in a ListView. 我有一个行列表,其中包含画笔,线条粗细等属性,我有一个自定义图例,它是ListView中的GridView。 What I want to accomplish is to draw the actual lines (with the Brush and thickness attributes) in the ListView to represent each line.
我想要完成的是在ListView中绘制实际线条(使用画笔和厚度属性)来表示每一行。 Currently I have two columns, one for color and one for thickness.
目前我有两个列,一个用于颜色,一个用于厚度。 However, the color column is in hex, so it's not very useful.
但是,颜色列是十六进制的,所以它不是很有用。
Or, if it makes it simpler, it's enough to draw a square of the color under the color column instead of lines. 或者,如果它变得更简单,则足以在颜色列下方绘制颜色的正方形而不是线条。
Any links or tutorials are appreciated. 任何链接或教程表示赞赏。 I am not familiar with drawing shapes/canvas/etc.
我不熟悉绘制形状/画布/等。 in general, so I am a little lost.
一般来说,所以我有点失落。
Much appreciated! 非常感激!
I would use a Rectangle
to draw the line and bind the Height
to the thickness value and the Fill
to the color value. 我将使用
Rectangle
绘制线条并将Height
绑定到厚度值,将Fill
绑定到颜色值。 Use the CellTemplate
and set it to one of the following in the GridViewColumn
. 使用
CellTemplate
并将其设置为GridViewColumn
中的以下之一。
<DataTemplate x:Key="ThicknessTemplate">
<Rectangle Height="{Binding LineThickness}" Width="10" Fill="{Binding LineColor}"/>
<DataTemplate/>
<DataTemplate x:Key="ColorTemplate">
<Rectangle Height="10" Width="10" Fill="{Binding LineColor}"/>
<DataTemplate/>
Here is a couple of links 这是一些链接
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.