2

I have a canvas that consists of different UserControls in WPF/XAML. In one of these controls I have a region that has to be transparent so the elements behind it are visible. However, due to the complex structure of this control I cannot just set the background to transparent or anything because there is another element in that usercontrol that is lets say moving behind it and cannot be transparent. So I want to have a region that seems transparent eventhough there is something else still behind it.

The only thing I could come up with is to use a VisualBrush and display exactly that region of my canvas on top of the region that has to look like if it was transparent. I wanted to do this in WPF and not XAML since I need to adjust the viewbox exactly so that the content is exactly the content that is behind that part. However, this does not seem to work at all. Here is the WPF code:

Rectangle rect = new Rectangle();
rect.HorizontalAlignment = HorizontalAlignment.Stretch;
rect.VerticalAlignment = VerticalAlignment.Stretch;

VisualBrush VisualBrush1 = new VisualBrush();
VisualBrush1.Visual = MainCanvas;
VisualBrush1.Stretch = Stretch.None;
rect.Fill = VisualBrush1;

RectTest.Child = rect;

BorderTest is the border that I defined in the xaml code that has to be transparent (it has a certain width and height). I did not set the viewbox properties yet since this is already not working. I was expecting that at least some part of the canvas would already be displayed inside my "borderTest"... Someone has an idea of my problem or can point me to some code where they do similar stuff? I already found a lot on the internet but I cannot get this thing to work.

4

1 回答 1

1

好的,我以不同的方式解决了这个问题:我在我的用户控件中的画布上添加了一个剪辑区域,该区域需要透明,因此那里没有显示任何内容,因此背景中的画布变得可见。不管怎么说,还是要谢谢你!

于 2014-08-05T14:29:35.987 回答