SizeToContent not rendered correctly
See original GitHub issueI’m new to this project, so my apologies in advance if this has been covered elsewhere.
It apears that MaterialWindow does not render the correct dimensions when using SizeToContent.
For example…
<mde:MaterialWindow x:Class="ClrVpin.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:clrVpin="clr-namespace:ClrVpin"
xmlns:materialDesign="http://materialdesigninxaml.net/winfx/xaml/themes"
xmlns:mde="https://spiegelp.github.io/MaterialDesignExtensions/winfx/xaml"
mc:Ignorable="d"
d:DataContext="{d:DesignData }"
WindowStartupLocation="CenterScreen"
ResizeMode="NoResize"
SizeToContent="WidthAndHeight"
Width="300" Height="250"
Title="ClrVpin" WindowState="Normal">
Yields the MaterialWindow plus also the underlying Window…
My workaround is to manually specify Width and Height, but this is a little painful for windows that I’d prefer dynamically size to the content.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:1
- Comments:5
Top Results From Across the Web
WPF SizeToContent not working when WindowStyle="None"
I am trying to remove all chrome (border and title). I can do this however the width does not size correctly. <Window x:Class="ActiveWords....
Read more >SizeToContent not sizing correctly · Issue #2471
I have made a message box for one of my programs but it is not sizing as it should I have got SizeToContent="WidthAndHeight"...
Read more >[BUG] Rendering bug when SizeToContent is set. #378
If I allow resize on the window, as soon as I drag the corner the layout updates and the problem goes away. Not...
Read more >RadWindow with SizeToContent="True" not resized
I am trying to use RadWindow as a Dialog window with XAML similar to this: <Grid> <Grid.RowDefinitions> <RowDefinition/>
Read more >SizeToContent concerns with RadWindow in UI for WPF
Hi Greg, Setting the SizeToContent property while having a specific Width and Height set is not possible in the current version of RadWindow ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Hi @markmov, my apologies for not replying sooner… but the email notification got lost in my spam folder 😦
Thanks for the tip. The Loaded handler works a treat…
Loaded += (_, _) => SizeToContent = SizeToContent.WidthAndHeight;
Regarding the extra pixel at the bottom, is this the sort of artifact you’re seeing without applying the ContentRendered hack?
If so, try this…
UseLayoutRounding="True"
in xaml (or code behing)And as a bonus, it should also remove the pixel artifacts in the nav bar too (only noticable if you’re using a dark theme heading style).
Essentially I suspect the root issue here is the windows scaling that is being applied, especially for users on high resolution screens (eg. 4k).
One thing I’ve just noticed… whilst explicitly assiging the SizeToContent within the Loaded event does assign the correct with/height, it unfortunately breaks WindowStartupLocation CentreScreen/Owner. It looks like the window isn’t repositioned to account for the (reduced) size.
Whilst it’s possible to offset this with a bit of math, it looks like making a similar change in ContentRendered is simpler as it doesn’t suffer the same problem.
Plus the code above will only perform the content sizing if it’s needed, e.g. in xaml
SizeToContent=SizeToContent.WidthAndHeight