0

I wanted to know if I can get a portion of a canvas (or other panel) in WPF.

I have tried this in XAML:

<Rectangle Margin="1">
    <Rectangle.Fill>
          <VisualBrush Visual="{Binding ElementName=Grid1, Mode=OneWay}"/>
    </Rectangle.Fill>
</Rectangle>

Wherein Grid1 is a Grid with 1 child control (a command button) But the rectangle displays the whole grid.

I wanted to get a portion of it, like this: Getting a portion of a Canvas (or grid) as visualBrush

On the image, a parent Grid (with pattern) holds a control (a textbox, button and a rectangle (or canvas or any panel)). The rectangle (shaded with transparent green as indicator only) should get the image (or a screenshot I don't know) behind it and assign the retrieved element to another rectangle as VisualBrush.

Hoping for your answer. Thanks.

Fer
  • 1
  • one way to acheive this is by scaling and translating your canvas at the same time – tabby May 23 '17 at 04:26
  • How? I'm a bit new to WPF. Thanks. – Fer May 23 '17 at 04:30
  • Check this for screenshot https://stackoverflow.com/questions/24466482/how-to-take-a-screenshot-of-a-wpf-control. You could just crop the image and use as ImageBrush http://www.c-sharpcorner.com/uploadfile/mahesh/using-imagebrush-in-wpf/ – Miguel May 23 '17 at 05:03
  • Whatever you try to do, I get a real bad feeling about this... You should probably describe more about what you want to achieve (in terms of visible result and behavior). There are only few situations where you want to re-use a part of the visual tree to appear at a second location. – grek40 May 23 '17 at 07:29

0 Answers0