WinUI SizeToContent #9404
-
I am trying to make a simple dialog app for desktop alerting. This was quite easy in WPF as I could use SizeToContent to have the app resize itself to the content generated. I have not found a way to do this as WinUI app does not resize to the content in the Main Window. I chose to try to move to WinUI because a self contained WPF app is ginormous. WinUI is still large but a fraction of the size of a WPF app. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 8 replies
-
Up. Did you find a solution? |
Beta Was this translation helpful? Give feedback.
-
Add a private void OnRootSizeChanged(object sender, SizeChangedEventArgs e)
{
var elm = (FrameworkElement)sender;
elm.SizeChanged -= OnRootSizeChanged;
// Edit from original: account for scaling
var scale = elm.XamlRoot.RasterizationScale;
var height = (int)Math.Ceiling(elm.DesiredSize.Height * scale);
var width = (int)Math.Ceiling(elm.DesiredSize.Width * scale);
AppWindow.ResizeClient(new(width, height));
Activate();
} This should be a good replacement, unless I'm missing something. |
Beta Was this translation helpful? Give feedback.
@gbohrn I think not calling
Activate
before the initialSizeChanged
should suffice.