Transparent border in WPF programmatically Transparent border in WPF programmatically wpf wpf

Transparent border in WPF programmatically


This is because you can't just cast a Color to be a Brush. use the Transparent brush instead

border.Background = Brushes.Transparent;


Use a SolidColorBrush:

border.Background = new SolidColorBrush(Colors.Transparent);

The VisualBrush has a different purpose. See an overview of the main types of WPF brushes here:

http://msdn.microsoft.com/en-us/library/aa970904.aspx


You can also create a SolidColorBrush with transparent color:This will create a fully transparent color

border.Background = new SolidColorBrush(Color.FromArgb(0, 0, 0, 0));

but you can also make semitransparent color by changing alpha (this will look like 50% transparent red:

border.Background = new SolidColorBrush(Color.FromArgb(128, 255, 0, 0));