SizeToContent border bug
This isn't part three of my theme series as I promised, but instead a random discovery which is after all what I subtitled this blog with. :) I'll get back to that in due course!
Instead, while building a dialog box today, I came across a very weird bug which seemed to have apparent cause. Can you see it?
Those with keen eyes will spot a distracting single pixel width black border along the inside edge of the window on the right and bottom sides (click the image to see it a bit clearer at the original size). This only seemed to kick in once I enabled the SizeToContent property and set it to WidthAndHeight.
SizeToContent is something very useful and not something I wanted to disable, it would let my window resize according to the content inside it which means if the user opens that expander, the window would grow to account for the extra space needed. All very WPF.
None of the child controls were causing it either, as you can see, I had not yet started to style the dialog yet.
After some poking around, I pinned down an option that seemed to be a workaround solution, enabling the SnapsToDevicePixels property on the Window:
Or in XAML:
<Window x:Class="Nox.Amuse.Dialogs.QuickConnectSetupDialog"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Quick Connection" ResizeMode="NoResize"
WindowStartupLocation="CenterOwner" x:Name="DialogWindow"
SizeToContent="WidthAndHeight"
ShowInTaskbar="False" SnapsToDevicePixels="True">
As far as I can work out, the bug was caused by my window sizing down to my content, but not quite enough (half a pixel or so, which renders as the greyish single pixel-width lines). SnapToDevicePixels does what it says on the tin, it forces the window to clip down to whole pixels. Feel free to comment if you I've not got this explanation quite right!
After applying the property and running again, I just have the regular border again:
Hope this helps others who get caught by this one!