-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Description
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.
In this image, you can see the incorrect text colour and lack of selection highlight colour:
Reproduction Steps
- Create a new WPF project and set it to use .NET 9 RC 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
- Set EnableWindowsForms to true in the project
- 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>
- Enable dark mode in Windows
- Build and run the app
- Observe the rendering issues on the background of the WindowsFormsHost
- Close the app
- Replace the Forms:Control in the WindowsFormsHost with a Forms:DateTimePicker
- Switch the system to light mode
- Build and run the app
- 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