如何在WPF中制作反射效果? (来自代码)

发布于 2024-08-22 02:30:55 字数 167 浏览 8 评论 0原文

我需要在 WPF 中有一些镜像对象。我有一个包含一些内容的 Canvas,并且我需要 50 个视觉克隆,如果我修改源上的某些内容,则应该在这些克隆中更新它。 我知道通过将 VisualBrush 的 Visual 绑定到元素在 XAML 中很容易做到,但似乎可以从代码中做到这一点。

有人可以帮忙吗?

I need to have some mirror objects in WPF. I have a Canvas with some content, and I need 50 visual clones, and if I modify something on the source, it should be updated in these clones.
I know it is easy to do in XAML by binding the Visual of a VisualBrush to the element, but can's seem to do this from code.

Can anyone help ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

又怨 2024-08-29 02:30:55

好吧,同时我找到了解决方案(Via Sese)。如果有人感兴趣,请在下面找到它:

VisualBrush VisualBrush1 = new VisualBrush();
VisualBrush1.TileMode = TileMode.FlipXY;
VisualBrush1.Viewport = new Rect(0.5, 0.5, 0.5, 0.5);

Binding bb = new Binding { ElementName = "button1" };
BindingOperations.SetBinding(VisualBrush1,VisualBrush.VisualProperty, bb);
rectangle1.Fill = VisualBrush1;

在 XAML 中:

<Grid>
        <Button Height="39"
                Margin="82,20,87,0"
                Name="button1"
                VerticalAlignment="Top">Button</Button>
        <Rectangle Margin="82,56,87,0"
                   Name="rectangle1"
                   Height="37"
                   VerticalAlignment="Top">            
        </Rectangle>
    </Grid>

也许您会发现这很有用,
丹尼尔

Ok, meanwhile I have found the solution (Via Sese). If anyone is interested, find it below:

VisualBrush VisualBrush1 = new VisualBrush();
VisualBrush1.TileMode = TileMode.FlipXY;
VisualBrush1.Viewport = new Rect(0.5, 0.5, 0.5, 0.5);

Binding bb = new Binding { ElementName = "button1" };
BindingOperations.SetBinding(VisualBrush1,VisualBrush.VisualProperty, bb);
rectangle1.Fill = VisualBrush1;

and in XAML:

<Grid>
        <Button Height="39"
                Margin="82,20,87,0"
                Name="button1"
                VerticalAlignment="Top">Button</Button>
        <Rectangle Margin="82,56,87,0"
                   Name="rectangle1"
                   Height="37"
                   VerticalAlignment="Top">            
        </Rectangle>
    </Grid>

Maybe you will find this usefull,
Daniel

青萝楚歌 2024-08-29 02:30:55

Take a look at this example of creating an attached behavior. You could use the behavior and just create and attach an instance using code, or you could use the code in the example directly to create the reflections.

枫林﹌晚霞¤ 2024-08-29 02:30:55

这是我很久以前写的一个在代码中构建反射效果的控件:

http://www.nbdtech.com/Blog/archive/2007/11/21/WPF-Reflection-Control.aspx

Here's a control I wrote a long time ago that builds the reflection effect in code:

http://www.nbdtech.com/Blog/archive/2007/11/21/WPF-Reflection-Control.aspx

豆芽 2024-08-29 02:30:55

如果您需要的只是一个简单的反射,这里有一篇链接到教程的文章,更有趣的是,您可以使用一个现成的控件(在 Infragistics.Toybox.dll 中)——不过,请确保首先检查其许可证,我不知道它的状态如何。

http://blogs.infragistics。 com/blogs/grant_hinkson/archive/2007/01/14/wpf-reflection-control.aspx

If all you need is a simple reflection, here is a post linking to a tutorial and, more interestingly, a ready-made control you can just use (in Infragistics.Toybox.dll) -- make sure to first check its license though, I don't know what its status is.

http://blogs.infragistics.com/blogs/grant_hinkson/archive/2007/01/14/wpf-reflection-control.aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文