如何在.cs文件和XAML文件中的元素周围创建绿线边框

时间:2014-01-06 14:55:30

标签: c# wpf xaml border

我想在WindowsFormsHost上创建一个边框。怎么做?

在.cs文件中:

 WindowsFormsHost Host = new WindowsFormsHost();

并在xaml中:

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

2 个答案:

答案 0 :(得分:3)

System.Windows.Border类是Decorator类型,这意味着它可以有一个Child元素。在这种情况下,您的孩子将是WindowsFormsHost

XAML:

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

答案 1 :(得分:1)

使用border类:

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();