Why are my WPF window sizes defaulting to be huge

后端 未结 3 1144
清酒与你
清酒与你 2020-12-20 11:16

I have a wpf application with a few forms. At design time they are small, and they are not set to auto size. However at run time they are giant, even with no content in them

3条回答
  •  天涯浪人
    2020-12-20 11:48

    Why don't you just add a:

    Height="296" Width="634"
    

    to the Window definition? I'm not sure where the default size comes from but I've set specific sizes on my windows to get around this. Then I dynamically resize in the application startup code.

    I'm hoping that WPF will have a pack-like feature where it recursively sets controls based on the preferred sizes of the sub-controls (Swing and wxPython both had this feature) so you may want to go looking for that.


    Actually, a bit of searching has turned up the Window.SizeToContent property which may be what you're looking for. Its default is Manual but, if you set it to one of the other values (Width, Height or WidthAndHeight), you may see a better presentation.

    In fact, I just nicked over to the Windows laptop and entered:

    SizeToContent="WidthAndHeight"
    

    into the Window definition and it looks perfectly sized. So, I'd suggest giving that a try and seeing if it fixes (or at least works around) your problem.

提交回复
热议问题