How do you keep the WPF window sized to content with an Expander after resize

前端 未结 5 579
伪装坚强ぢ
伪装坚强ぢ 2021-01-31 14:07

I\'ve got a WPF window with SizeToContent=\"Height\". This window contains an that displays a list of recent activity. What I\'d lik

5条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-01-31 14:36

    The easiest way to cope is to take manual resizing out of the equation by setting ResizeMode="NoResize" on the window. However, if you have WindowStyle="None" I've noticed that on Vista Aero this causes the window to completely shed the "chrome" and the window looks awkward. Also, this somewhat of a cop out since it looks like you want to give the user resizing capabilities.

    The problem is that you have two conflicting goals: 1.) you always want SizeToContent="Height" when collapsing the expander control, 2.) you want SizeToContent="Height" when expanding the expander control unless the user has manually resized the window (SizeToContent="Manual"), in which case you'd like to return to the user's manual height.

    Yikes. I don't think you can get around saving the expanded height yourself. WPF won't remember the user's manual height upon expanding once you've reverted back to SizeToContent="Height" in your collapsed event handler.

提交回复
热议问题