How to make reflection effect in WPF? (from code)

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 in the source, it needs to be updated in these clones. I know this is easy to do in XAML by attaching Visual VisualBrush to an element, but it might seem like this is being done from code.

Can anyone help?

+2
source share
4 answers

Ok, meanwhile I found a solution (Via Sese). If someone is interested, find him 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>

You may find this helpful, Daniel

+3
source

. , .

+1

All Articles