From 4d01054beab6e22cf1ec759dff1b003310ad9f48 Mon Sep 17 00:00:00 2001 From: SyedAbdulAzeemSF4852 Date: Thu, 10 Jul 2025 16:59:39 +0530 Subject: [PATCH 1/8] [Windows] Fix for Picker CharacterSpacing property not being applied to Title and Picker Items --- .../Windows/CharacterSpacingConverter.cs | 21 +++++++ .../src/Platform/Windows/PickerExtensions.cs | 28 ++++++++- .../Windows/Styles/MauiComboBoxStyle.xaml | 2 +- .../Platform/Windows/Styles/Resources.xaml | 58 +++---------------- 4 files changed, 56 insertions(+), 53 deletions(-) create mode 100644 src/Core/src/Platform/Windows/CharacterSpacingConverter.cs diff --git a/src/Core/src/Platform/Windows/CharacterSpacingConverter.cs b/src/Core/src/Platform/Windows/CharacterSpacingConverter.cs new file mode 100644 index 000000000000..10f70091d497 --- /dev/null +++ b/src/Core/src/Platform/Windows/CharacterSpacingConverter.cs @@ -0,0 +1,21 @@ +using System; + +namespace Microsoft.Maui.Platform; + +internal sealed class CharacterSpacingConverter : UI.Xaml.Data.IValueConverter +{ + public object Convert(object value, Type targetType, object parameter, string language) + { + if (value is double characterSpacing) + { + return characterSpacing.ToEm(); + } + + return 0; + } + + public object ConvertBack(object value, Type targetType, object parameter, string language) + { + throw new NotSupportedException(); + } +} \ No newline at end of file diff --git a/src/Core/src/Platform/Windows/PickerExtensions.cs b/src/Core/src/Platform/Windows/PickerExtensions.cs index 30f33ec854df..f94c04f627bb 100644 --- a/src/Core/src/Platform/Windows/PickerExtensions.cs +++ b/src/Core/src/Platform/Windows/PickerExtensions.cs @@ -74,7 +74,33 @@ public static void UpdateSelectedIndex(this ComboBox nativeComboBox, IPicker pic public static void UpdateCharacterSpacing(this ComboBox nativeComboBox, IPicker picker) { - nativeComboBox.CharacterSpacing = picker.CharacterSpacing.ToEm(); + var characterSpacing = picker.CharacterSpacing.ToEm(); + nativeComboBox.CharacterSpacing = characterSpacing; + + if (nativeComboBox.IsLoaded) + { + ApplyCharacterSpacingToSelectedItem(nativeComboBox, characterSpacing); + } + else + { + nativeComboBox.OnLoaded(() => + { + ApplyCharacterSpacingToSelectedItem(nativeComboBox, characterSpacing); + }); + } + } + + static void ApplyCharacterSpacingToSelectedItem(ComboBox nativeComboBox, int characterSpacing) + { + var contentPresenter = nativeComboBox.GetDescendantByName("ContentPresenter"); + if (contentPresenter != null) + { + var textBlock = contentPresenter.GetFirstDescendant(); + if (textBlock != null) + { + textBlock.CharacterSpacing = characterSpacing; + } + } } public static void UpdateFont(this ComboBox nativeComboBox, IPicker picker, IFontManager fontManager) => diff --git a/src/Core/src/Platform/Windows/Styles/MauiComboBoxStyle.xaml b/src/Core/src/Platform/Windows/Styles/MauiComboBoxStyle.xaml index f52b6279a916..4fbbe790cd54 100644 --- a/src/Core/src/Platform/Windows/Styles/MauiComboBoxStyle.xaml +++ b/src/Core/src/Platform/Windows/Styles/MauiComboBoxStyle.xaml @@ -6,7 +6,7 @@ diff --git a/src/Core/src/Platform/Windows/Styles/Resources.xaml b/src/Core/src/Platform/Windows/Styles/Resources.xaml index 037beebde72e..06b0f99063ee 100644 --- a/src/Core/src/Platform/Windows/Styles/Resources.xaml +++ b/src/Core/src/Platform/Windows/Styles/Resources.xaml @@ -13,57 +13,13 @@ true - - - 350 - - - - - - + + + + + + + 350 + + + + + +