Using Visual Studio 2022, .NET 6, WPF (with MVVM), Mahapps.Metro (+IconPacks), C#.
I'm using Mahapps.Metro and I defined a style for the ComboBox so that it shows a clear text button.
<Style TargetType="ComboBox" x:Key="{x:Type ComboBox}"
BasedOn="{StaticResource MahApps.Styles.ComboBox}">
<Setter Property="FontFamily" Value="Segoe UI"/>
<Setter Property="FontSize" Value="9"/>
<Setter Property="mah:TextBoxHelper.ClearTextButton" Value="True"/>
</Style>
This seems to work perfectly...
However... When I also define a style for TextBlock then the X icon is suddenly shown as the letter 'r'.
The XAML for my ComboBox is quite simple...
<ComboBox x:Name="CustomerCustomerCategoryComboBox"
Grid.Column="2" Grid.Row="2"
MinWidth="100"
Grid.ColumnSpan="3"
I'm completely baffled to be honest. I have no clue whatsoever as to what causes this behaviour. Has someone else experienced this or, better even, know what I can do to solve this?
I've tried all sorts of things... removing the TexBlock style solves it obviously but that way I lose the style for all my other TexBlocks.
Tried playing around with the Style settings, googled my problem with several keywords and phrases but I seem to be the only one?


As you can see from the default style for the clear button here , it uses:
TextBoxHelper.ButtonContentasContent, which provides the string"r".TextBoxHelper.ButtonFontFamilyasFontFamily, which provides the fontMarlett.In other words, a special font is used that has symbols instead of letters and
ris the cross symbol.In the live element tree you can see that the clear button uses a
TextBlockinternally.Your style is a so-called implicit style, meaning it specifies the control type itself as
x:Key. Therefore it will apply to allTextBlocks in scope that do not explicitly set a different style. This also applies to theTextBlocks that displays the cross symbol for the clear button. You effectively override the default font family.Overriding control styles globally is not favorable, especially if you use external libraries that depend on default framework styles.
TextBlockstyle and apply it where you really need it or create an implicit style in a limited local scope (Resourcesof a view or control) where you can be sure that it does not intefere with other styles.TextBlocknested deep inside a control template is actually defined (without investigating the external code as well each time) and it might change in the future, too. Plus, keeping track of these implementation details is hard. In libraries that are not open source, checking the source is not even an option.As a potential quick workaround, you could use the fact, that the
TextBoxHelperalso provides a propertyButtonContentTemplatefor specifying a content template, where you can remove the effects of your customTextBlockstyle. However, this approach has the same issues as stated above, maintenance and side effects welcome in the long run.