简体   繁体   中英

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

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;

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 , eg by passing the R, G, and B values to the FromRgb method.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM