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

114 views Asked by At

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.

1

There are 1 answers

0
Eric On

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)