使用System.Drawing.Color在WPF中绘制一行 [英] Use System.Drawing.Color to draw a line in WPF
问题描述
如何使用 System.Drawing.Color
在XAML中画一条线?没有转换器的解决方案会很好。
How can I draw a line in XAML using a System.Drawing.Color
? A solution without a converter would be nice.
XAML:
< Line
X1 =10Y1 =10
X2 =20Y2 =10
笔画={装订颜色}StrokeThickness =4/& code>
<Line
X1="10" Y1="10"
X2="20" Y2="10"
Stroke="{Binding Color}" StrokeThickness="4" />
代码:
System.Drawing.Color Color = System.Drawing.Color.Black;
推荐答案
您需要绑定刷机到 Stroke 属性,特别是 SolidColorBrush 接受颜色。
You need to bind a Brush to the Stroke property, in particular a SolidColorBrush, which accepts a color.
但是,您需要从 System.Drawing.Color 到 System.Windows .Media.Color 将R,G和B值传递到 FromRgb 方法。
However, you need to convert from System.Drawing.Color to System.Windows.Media.Color, e.g. by passing the R, G, and B values to the FromRgb method.
这篇关于使用System.Drawing.Color在WPF中绘制一行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!