0

I'll try to explain my problem clearly.

I have a working code in WinForms that has a Board (PictureBox) that shows an image thats generated from a list of users controls (win-forms) by the function UserControl.BitmapCopy() for each user control.

This process begins with a blank image (Graphic type), and for each user control I draw it in a specific location with the function BitmapCopy() of the user control.

The result is an image that looks like a real form (with buttons,labels,etc.), but it’s just an image.

Then I show this image in a picture Box.

Now I need to implement this code in WPF, but I can’t generate an image of each user control with BitmapCopy().

I found this code that does it, so now I can generate a bitmap for each user control, but I don’t know what is the best way to create the Big Board that eventually shows a bitmap that has all the user controls images inside it, in different locations.

I would appreciate any help.

Community
  • 1
  • 1
Guy P
  • 1,395
  • 17
  • 33

1 Answers1

1

This is the equivalent in WPF:

<Window x:Class="MiscSamples.VisualBrush"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        Title="VisualBrush" Height="300" Width="300" x:Name="Window">
    <StackPanel>
        <TextBlock Text="Hi, Im a Window!"/>
        <TextBox Text="This is a TextBox"/>
        <Slider Width="200"/>
    </StackPanel>
    <Window.ToolTip>
        <ToolTip DataContext="{Binding PlacementTarget, RelativeSource={RelativeSource Self}}">
            <Grid Height="400" Width="400">
                <Grid.Background>
                    <VisualBrush Visual="{Binding}"/>
                </Grid.Background>
            </Grid>
        </ToolTip>
    </Window.ToolTip>
</Window>

The Window's ToolTip consists of a grid painted with VisualBrush whose Visual is the Window itself. It looks like this:

enter image description here

As you can see, Exactly 0 lines of C# code are required to achieve the same in WPF.

Federico Berasategui
  • 43,562
  • 11
  • 100
  • 154
  • Thanks for your help. But I have a list of user controls, I don't need a declaration in the XAML file. I have to generate this image by the list. – Guy P Mar 24 '13 at 12:17
  • @Guy this was just to give you an example of how to use the `VisualBrush`, you can adapt it to whatever you need. – Federico Berasategui Mar 24 '13 at 14:05
  • Yes I know, thanks for that, but is it possible to bind it NOT to "Self" but to some private list ? Thanks again. – Guy P Mar 24 '13 at 16:09