为图像控件添加边框可防止图像显示 WPF
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/14780105/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Adding a border to image control prevents image from displaying WPF
提问by JeffG
I have a perplexing problem that makes no sense to me - I am trying to place a border round an image control in WPF. The image control displays an image perfectly (I have loaded through code behind and XAML and both work fine). However when I place a border around the image control the image does not appear at all. This happening with three image controls all with identical config. Does anyone know why this is or how I can fix it? Many thanks, Jeff.
我有一个对我来说毫无意义的令人困惑的问题 - 我试图在 WPF 中的图像控件周围放置一个边框。图像控件完美地显示了图像(我已经通过隐藏代码和 XAML 加载了并且都工作正常)。但是,当我在图像控件周围放置边框时,图像根本不会出现。发生这种情况的三个图像控件都具有相同的配置。有谁知道这是为什么或我如何解决它?非常感谢,杰夫。
XAML (with border commented out) is below:
XAML(带注释掉的边框)如下:
<!--<Border BorderBrush="Black" BorderThickness="2" Margin="201,172,618,450" Grid.Column="1">-->
<Image Name="imgFault11" Stretch="Fill" Grid.Column="1" Margin="200,172,619,450">
<!--</Border>-->
采纳答案by paparazzo
You are putting both in Grid.Column="1"
Put the image in the border
Start with no margins
你把两者都放在 Grid.Column="1"
把图像放在边框中
开始没有边距
<Border BorderBrush="Black" BorderThickness="2" Grid.Column="1">
<Image Name="imgFault11" Stretch="Fill">
</Border>
回答by Kenneth Wilson
You may have to send the border to the Background. Once you add this it overlays the image. Right click the border .. go to order and then choose "Send to Back". The border control is in the toolbox. This is all a little messy though as getting the border to match the image box size takes time to get right and then you have one control on top of another..etc.
您可能必须将边框发送到背景。一旦你添加了它,它就会覆盖图像。右键单击边框.. 转到订单,然后选择“发送到后面”。边框控件位于工具箱中。这有点混乱,因为让边框与图像框大小相匹配需要时间才能正确,然后您可以在另一个控件之上进行控制......等等。

