如何为图像添加边框?

时间:2014-04-03 09:16:43

标签: c# wpf

为什么我不能为我添加的图片添加边框?这段代码有什么问题?

<Border Name="imgBorder" BorderThickness="2">
    <Image Height="150" 
     HorizontalAlignment="Left" 
     Margin="90,239,0,0" Name="image1" 
     Stretch="Fill" VerticalAlignment="Top" 
     Width="200" 
     Source="/ControlsBasics-WPF;component/GalleryImages/Lighthouse.jpg" 
     ImageFailed="image1_ImageFailed" />

</Border>

1 个答案:

答案 0 :(得分:5)

边框颜色的默认值(即BorderBrush)为空,这意味着除非您指定其颜色,否则您将无法看到边框。 此外,您为图像的边距指定了一个疯狂的高值,它将在您的Image 90像素右侧和239在实际边框下绘制! 黑色边框的示例

<Border Name="imgBorder" BorderThickness="2" BorderBrush="Black">
            <Image Height="150" HorizontalAlignment="Left" Name="image1" Stretch="Fill" VerticalAlignment="Top" Width="200" Source="/ControlsBasics-WPF;component/GalleryImages/Lighthouse.jpg" ImageFailed="image1_ImageFailed" />

        </Border>