'How to resize the window to size a DockPanel's fill control in WPF?

I've written up an emulator using WPF. The window itself is basic:

<Window>
  <DockPanel>
    <Menu DockPanel.Doc="Top" .../>
    <StatusBar DockPanel.Doc="Bottom" .../>
    <ViewBox/>
  </DockPanel>
</Window>

The emulator runs fine within the ViewBox container. Window can be resized and such.

However, the original system ran in 640x480 pixels and I'd like to add an option to resize to that.

So... How I can resize the window such that ViewBox is exactly 640x480?

(Yes, I'm wanting to set the size of the only control free to size itself)

Additional: My emulator only uses the coordinates of the ViewBox for BitBlt purposes. It doesn't actually use the control itself.



Solution 1:[1]

I figured it out with some basic math:

Size window = Window.RenderSize;
Size viewbox = Viewbox.RenderSize;
Window.Width = window.Width - (viewbox.Width - 640);
Window.Height = window.Height - (vSize.Height - 480));

(Window/ViewBox being elements mentioned in original question)

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Eric