HandyControl
HandyControl copied to clipboard
Change SizeToContent in OnLoaded or OnSourceInitialized has no effect
Describe the bug hc:Window的继承类,如果在XAML中设定了SizeToContent="WidthAndHeight",在OnLoaded或者 OnSourceInitialized 里面修改SizeToContent为Manual会无效,窗口还是会自动变化。
产生原因: https://github.com/HandyOrg/HandyControl/blob/4735ebc812a3e4e264cd13865f512e0b360b154d/src/Shared/HandyControl_Shared/Controls/Window/Window.cs#L313
会导致在OnLoaded、OnSourceInitialized 之后SizeToContent更新一次,使得在这两个方法中设置的SizeToContent和窗口Width、Height被覆盖。
解决办法 在XAML中去掉SizeToContent属性设置,或者修改为非WidthAndHeight的值。
这个另外还引发了一个问题,因为在OnLoad以后SizeToContent了一次,一个原来通过在Onload里计算窗口尺寸并且让窗口居中显示的功能失败了。