Yoda
Yoda

Reputation: 18068

How to create green line border around an element in .cs file and XAML file

I would like to create a border over the WindowsFormsHost. How to do so?

In .cs file:

 WindowsFormsHost Host = new WindowsFormsHost();

and in the xaml:

 <WindowsFormsHost x:Name="Host"></WindowsFormsHost>

Upvotes: 0

Views: 497

Answers (2)

Alberto
Alberto

Reputation: 15941

Use the border class:

xaml:

<Border BorderThickness="1" BorderBrush="Green">
    <WindowsFormsHost x:Name="Host"></WindowsFormsHost>
</Border>

cs:

var myBorder = new Border();
myBorder.BorderBrush = Brushes.Green;
myBorder.BorderThickness = new Thickness(1);
myBorder.Child = new WindowsFormsHost();

Upvotes: 1

myermian
myermian

Reputation: 32515

The System.Windows.Border class is a type of Decorator, which means it can have a single Child element. In this case, your child would be the WindowsFormsHost.

XAML:

<Border BorderBrush="Green" BorderThickness="1">
   <WindowsFormsHost x:Name="Host"></WindowsFormsHost>
</Border>

Upvotes: 3

Related Questions