如何将图像覆盖在 WPF 中的图像上?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/21765677/
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
how to overlay an image over an image in WPF?
提问by Brian J
I'm trying to figure out how to overlay an image or textbox over an image in WPF. The base image will be hosting a video feed from a Kinect sensor and I want to overlay an image on it. For example the video feed will have a textbox on the feed that will update a counter or an image of a tree on top of the video feed.
我想弄清楚如何在 WPF 中的图像上覆盖图像或文本框。基本图像将托管来自 Kinect 传感器的视频源,我想在其上叠加一个图像。例如,视频提要将在提要上有一个文本框,该文本框将更新视频提要顶部的计数器或树的图像。
Is there a straightforward way of achieving this in the layout? Is it just a matter of changing properties or adding a canvas?
在布局中是否有一种直接的方法来实现这一点?这只是改变属性或添加画布的问题吗?
The below picture better illustrates what it is I'm trying to do:
下图更好地说明了我正在尝试做的事情:


回答by Firoz
You can use two transparent canvas inside the Grid without any row and column then place your objects in Back and front Canvas accordingly they will overlap
您可以在没有任何行和列的 Grid 中使用两个透明画布,然后将您的对象相应地放置在 Back 和 Front Canvas 中,它们将重叠
that is:
那是:
<Grid>
<VideoControl><!-- I've never tried video --></VideoControl>
<TextBlock Text="My Text" />
</Grid>
Usually you specify <Grid.ColumnDefinitions>and <Grid.RowDefinitions>but since you do not du that here the controls will overlap
通常你指定<Grid.ColumnDefinitions>并且<Grid.RowDefinitions>但是因为你没有在这里控制将重叠
HTH
HTH
回答by Default
The usual way for me to overlay items in WPF is just to put all of the elements in a Grid. If you do not define any Columns or Rows the elements will overlap.
我在 WPF 中覆盖项目的常用方法是将所有元素放在Grid. 如果您没有定义任何列或行,元素将重叠。
Example
例子
<Grid>
<Image Source="image on lowest layer" />
<Image Source="overlaying image" />
</Grid>

