views:

118

answers:

1

So basically, the MainWindow opens a second Window, let's say OptionsWindow. So in the OptionsWindow I want to show a visual of the MainWindow. I tried this, but didn't work:

<Rectangle Grid.Row="1" Margin="3" Height="100">
 <Rectangle.Fill>
  <VisualBrush Visual="{Binding Application.Current.MainWindow}" />
 </Rectangle.Fill>
</Rectangle>

Any help greatly appreciated.

EDIT:

I found the obvious answer:

windowPreview.Visual = Application.Current.MainWindow;

The only weird thing is that it calls the Loaded event of the MainWindow again and I have some code there that should only run when the MainWindow first loads. I though it would just show the current instance of the MainWindow. Any workaround on this?

A: 

If you put the load code in the constructor for the MainWindow that should only get called once per instance.

I'm not sure if it is a bug that WPF calls the Load event more than once for any given window, but it sounds like it might be by design for cases where a user closes and reloads the window...

Ben Childs
The weird thing is that the control inside the visual has no functionality at all. I guess it's calling the Loaded event because it actually re-drew it, but if that's the case, then it doesn't seem very convenient.
Carlo