When I set AppContext.SetSwitch("Switch.System.Windows.Controls.Text.UseAdornerForTextboxSelectionRendering", false); TextBox behaves normally, RichTextBox cannot display text. What is the reason for this result?
XAML:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*" />
<RowDefinition Height="*" />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Label Content="TextBox" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="25"></Label>
<TextBox Height="80" Width="500" Grid.Column="1" SelectionOpacity="1"></TextBox>
<Label Content="RichTextBox" Grid.Row="1" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="25"></Label>
<RichTextBox Height="80" Width="500" Grid.Row="1" Grid.Column="1" SelectionOpacity="1" Style="{StaticResource RichTextBoxStyle}"></RichTextBox>
</Grid>
.Net6:
Codebedhind:
public MainWindow()
{
AppContext.SetSwitch("Switch.System.Windows.Controls.Text.UseAdornerForTextboxSelectionRendering", false);
InitializeComponent();
}
.NET Framework 4.8
App.config:
<runtime>
<AppContextSwitchOverrides value="Switch.System.Windows.Controls.Text.UseAdornerForTextboxSelectionRendering=false"/>
</runtime>
Is it possible to make the results of RichTextBox behave the same as the results of TextBox without changing the xaml code?

The fact that the switch only applies to
TextBoxandPasswordBoxas stated in the docs.At least not using this, or any other, switch. Set the
SelectionOpacityprogrammatically if you don't want to touch the XAML markup? If you can call theAppContext.SetSwitchmethod in the code-behind, you might as well also set a property of a control.