Skip to content

WindowsFormsHost rendering broken with new fluent themes in .NET 9 #10044

@aquinn39

Description

@aquinn39

Description

When fluent themes are enabled, WindowsFormsHosts no longer render correctly; a black square renders on the background of them with random WPF content from other areas of the window rendered on top. Text renders white-on-white and with no selected text highlight colour on some controls in light mode.

In the image below, the WindowsFormsHosts is bordered in red. Notice the strange rendering in the top left that shows a black background with some content from elsewhere in the WPF window.
Image

In this image, you can see the incorrect text colour and lack of selection highlight colour:
Image

Reproduction Steps

  1. Create a new WPF project and set it to use .NET 9 RC 2
  2. Enable fluent themes in the project as described here: https://github.com/dotnet/core/blob/main/release-notes/9.0/preview/preview4/wpf.md#support-for-windows-11-theming
  3. Set EnableWindowsForms to true in the project
  4. Add the follow content to the main window (Yes, it is very poorly written XAML but it triggers the bug):
<Window
        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:local="clr-namespace:WPFNet9Test"
        xmlns:Forms="clr-namespace:System.Windows.Forms;assembly=System.Windows.Forms" x:Class="MainWindow"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800" FontSize="40" Loaded="Window_Loaded">
    <Grid>
        <CheckBox Content="CheckBox" Margin="68,79,0,0" VerticalAlignment="Top"/>
        <ComboBox HorizontalAlignment="Left" Margin="166,223,0,0" VerticalAlignment="Top" Width="120" SelectedIndex="0">
            <ComboBoxItem Content="Test"/>
        </ComboBox>
        <TextBlock HorizontalAlignment="Left" Margin="317,68,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"/>
        <WindowsFormsHost x:Name="hst1" HorizontalAlignment="Left" Height="155" Margin="68,265,0,0" VerticalAlignment="Top" Width="684">
            <Forms:DateTimePicker/>
        </WindowsFormsHost>
        <TextBlock HorizontalAlignment="Left" Margin="431,172,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"/>
        <CheckBox Content="CheckBox" Margin="29,183,0,0" VerticalAlignment="Top"/>
        <TextBlock HorizontalAlignment="Left" Margin="166,146,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top"/>

    </Grid>
</Window>
  1. Enable dark mode in Windows
  2. Build and run the app
  3. Observe the rendering issues on the background of the WindowsFormsHost
  4. Close the app
  5. Replace the Forms:Control in the WindowsFormsHost with a Forms:DateTimePicker
  6. Switch the system to light mode
  7. Build and run the app
  8. Observe the incorrect text colour and lack of selected text visual on the DateTimePicker

Expected behavior

  • The background of a WindowsFormsHost is a solid colour without any rendering artifacts.
  • Text renders black-on-white in light mode.
  • Text selection colour shows.

Actual behavior

  • The background of a WindowsFormsHost has various rendering artifacts taken from other areas of the WPF window.
  • Text renders white-on-white in light mode.
  • Text selection colour does not show.

Regression?

Yes, works fine in .NET 8 and .NET Framework and in .NET 9 without the fluent themes enabled.

Known Workarounds

No response

Impact

Breaks apps that rely on WindowsFormsHosts.

Configuration

.NET 9, AnyCPU, Windows 11 build 22631.4037.

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions