user2799180
user2799180

Reputation: 749

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;

Upvotes: 0

Views: 3356

Answers (1)

Oliver Hanappi
Oliver Hanappi

Reputation: 12336

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.

Upvotes: 3

Related Questions