Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Transparent border in WPF programmatically

It's trivial to generate a border (to use for Trackball events) transparent over the viewport in the XAML file:

<Border Name="myElement" Background="Transparent" />

But how do I do it in the .cs?

Border border = new Border();
**border.Background = (VisualBrush)Colors.Transparent;**
grid.Children.Add(viewport);
grid.Children.Add(border);

This does not work of course.

like image 487
Pedro Dusso Avatar asked Sep 28 '11 15:09

Pedro Dusso


1 Answers

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

border.Background = Brushes.Transparent;
like image 52
jk. Avatar answered Sep 19 '22 15:09

jk.