Use System.Drawing.Color to draw a line in WPF

人盡茶涼 提交于 2019-12-14 03:24:43

问题


How can I draw a line in XAML using a System.Drawing.Color? A solution without a converter would be nice.

XAML:

<Line X1="10" Y1="10" X2="20" Y2="10" Stroke="{Binding Color}" StrokeThickness="4" />

Code:

System.Drawing.Color Color = System.Drawing.Color.Black;

回答1:


You need to bind a Brush to the Stroke property, in particular a SolidColorBrush, which accepts a color.

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.



来源:https://stackoverflow.com/questions/19658064/use-system-drawing-color-to-draw-a-line-in-wpf

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!