diff --git a/tests/Titano.App.Tests/Visuals/VisualsSmokeTests.cs b/tests/Titano.App.Tests/Visuals/VisualsSmokeTests.cs index 65e1a41f..408c2020 100644 --- a/tests/Titano.App.Tests/Visuals/VisualsSmokeTests.cs +++ b/tests/Titano.App.Tests/Visuals/VisualsSmokeTests.cs @@ -48,6 +48,7 @@ public sealed class VisualsSmokeTests public void CardFitsTheDefaultGridSlot() => WpfHost.Run(() => { var card = SampleCard(); + Host(card); card.Measure(new Size(double.PositiveInfinity, double.PositiveInfinity)); Assert.Approximately(236, card.DesiredSize.Width, 0.5); Assert.LessOrEqual(card.DesiredSize.Height, (double)VirtualizingWrapPanel.ItemHeightProperty.DefaultMetadata.DefaultValue + 0.5); @@ -236,14 +237,22 @@ public sealed class VisualsSmokeTests private static RenderTargetBitmap Render(FrameworkElement element, double width, double height) { - element.Measure(new Size(width, height)); - element.Arrange(new Rect(0, 0, width, height)); - element.UpdateLayout(); + var host = Host(element); + host.Measure(new Size(width, height)); + host.Arrange(new Rect(0, 0, width, height)); + host.UpdateLayout(); var bitmap = new RenderTargetBitmap((int)width, (int)height, 96, 96, PixelFormats.Pbgra32); - bitmap.Render(element); + bitmap.Render(host); return bitmap; } + /// + /// Gives the element a visual parent, as in a real window: WPF fetches implicit and theme styles (and with them + /// templates) only once an element is initialized, which a bare element created in code never is. + /// + private static Border Host(FrameworkElement element) => + element.Parent as Border ?? new Border { Child = element }; + private static int Painted(BitmapSource bitmap) { var stride = bitmap.PixelWidth * 4;