From a13ba2fc17748167215926606ef414acc1c78e0e Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Thu, 21 May 2026 22:01:37 -0300 Subject: [PATCH 01/11] implement BooleanBoxes --- src/Controls/src/Core/GlobalNamespaces.cs | 1 + .../src/Core/Internals/BooleanBoxes.cs | 21 +++++++++++++++++++ 2 files changed, 22 insertions(+) create mode 100644 src/Controls/src/Core/Internals/BooleanBoxes.cs diff --git a/src/Controls/src/Core/GlobalNamespaces.cs b/src/Controls/src/Core/GlobalNamespaces.cs index 40c8a90ceba8..b3e66d084da1 100644 --- a/src/Controls/src/Core/GlobalNamespaces.cs +++ b/src/Controls/src/Core/GlobalNamespaces.cs @@ -1,3 +1,4 @@ global using Microsoft.Maui; global using Microsoft.Maui.Handlers; global using Microsoft.Maui.Platform; +global using Microsoft.Maui.Controls.Internals; diff --git a/src/Controls/src/Core/Internals/BooleanBoxes.cs b/src/Controls/src/Core/Internals/BooleanBoxes.cs new file mode 100644 index 000000000000..7a553e0f7572 --- /dev/null +++ b/src/Controls/src/Core/Internals/BooleanBoxes.cs @@ -0,0 +1,21 @@ +using System.Diagnostics.CodeAnalysis; + +namespace Microsoft.Maui.Controls.Internals; + +internal static class BooleanBoxes +{ + internal static readonly object TrueBox = true; + internal static readonly object FalseBox = false; + + internal static object Box(bool value) => + value ? TrueBox : FalseBox; + + [return: NotNullIfNotNull(nameof(value))] + internal static object? Box(bool? value) => + value switch + { + true => TrueBox, + false => FalseBox, + null => null, + }; +} \ No newline at end of file From 70b5eb066ead1847ffb6a0a330861e3cb89a39e7 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Thu, 21 May 2026 22:08:19 -0300 Subject: [PATCH 02/11] inital work --- src/Controls/src/Core/ActivityIndicator/ActivityIndicator.cs | 2 +- src/Controls/src/Core/CheckBox/CheckBox.cs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Controls/src/Core/ActivityIndicator/ActivityIndicator.cs b/src/Controls/src/Core/ActivityIndicator/ActivityIndicator.cs index 0498db4a2c80..8d2663c77b55 100644 --- a/src/Controls/src/Core/ActivityIndicator/ActivityIndicator.cs +++ b/src/Controls/src/Core/ActivityIndicator/ActivityIndicator.cs @@ -16,7 +16,7 @@ namespace Microsoft.Maui.Controls public partial class ActivityIndicator : View, IColorElement, IElementConfiguration, IActivityIndicator { /// Bindable property for . - public static readonly BindableProperty IsRunningProperty = BindableProperty.Create(nameof(IsRunning), typeof(bool), typeof(ActivityIndicator), default(bool)); + public static readonly BindableProperty IsRunningProperty = BindableProperty.Create(nameof(IsRunning), typeof(bool), typeof(ActivityIndicator), BooleanBoxes.FalseBox); /// Bindable property for . public static readonly BindableProperty ColorProperty = ColorElement.ColorProperty; diff --git a/src/Controls/src/Core/CheckBox/CheckBox.cs b/src/Controls/src/Core/CheckBox/CheckBox.cs index 03423defc58c..5fd88fe31b1f 100644 --- a/src/Controls/src/Core/CheckBox/CheckBox.cs +++ b/src/Controls/src/Core/CheckBox/CheckBox.cs @@ -29,7 +29,7 @@ public partial class CheckBox : View, IElementConfiguration, IBorderEl /// Bindable property for . This is a bindable property. public static readonly BindableProperty IsCheckedProperty = - BindableProperty.Create(nameof(IsChecked), typeof(bool), typeof(CheckBox), false, + BindableProperty.Create(nameof(IsChecked), typeof(bool), typeof(CheckBox), BooleanBoxes.FalseBox, propertyChanged: (bindable, oldValue, newValue) => { if (bindable is not CheckBox checkBox) From 1800a4e8f6680137e14543275f141254ea1f0fa7 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Thu, 21 May 2026 22:21:12 -0300 Subject: [PATCH 03/11] Apply BooleanBoxes to bool BindableProperties in Controls.Core Replace raw true/false/default(bool) literals with BooleanBoxes.TrueBox and BooleanBoxes.FalseBox in BindableProperty.Create defaultValue arguments across all bool-typed BindableProperties in Controls.Core. This avoids repeated boxing allocations on every property default-value access. Added using Microsoft.Maui.Controls.Internals; to 26 files that did not already have it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> # Conflicts: # src/Controls/src/Core/SwipeView/SwipeItem.cs --- src/Controls/src/Core/AppLinkEntry.cs | 3 ++- src/Controls/src/Core/Cells/Cell.cs | 2 +- src/Controls/src/Core/Cells/SwitchCell.cs | 3 ++- src/Controls/src/Core/ContentPage/ContentPage.cs | 3 ++- .../src/Core/DragAndDrop/DragGestureRecognizer.cs | 5 +++-- .../src/Core/DragAndDrop/DropGestureRecognizer.cs | 3 ++- src/Controls/src/Core/Entry/Entry.cs | 2 +- src/Controls/src/Core/FlyoutPage/FlyoutPage.cs | 4 ++-- src/Controls/src/Core/FontImageSource.cs | 3 ++- src/Controls/src/Core/Frame/Frame.cs | 3 ++- .../src/Core/Handlers/Shell/Tizen/ShellContentItemView.cs | 2 +- .../src/Core/Handlers/Shell/Tizen/ShellFlyoutItemView.cs | 2 +- .../src/Core/Handlers/Shell/Tizen/ShellSectionItemView.cs | 2 +- src/Controls/src/Core/IndicatorView/IndicatorView.cs | 2 +- src/Controls/src/Core/InputView/InputView.cs | 6 +++--- src/Controls/src/Core/Items/CarouselView.cs | 8 ++++---- src/Controls/src/Core/Items/GroupableItemsView.cs | 3 ++- src/Controls/src/Core/Items/ReorderableItemsView.cs | 5 +++-- src/Controls/src/Core/Layout/Layout.cs | 3 ++- src/Controls/src/Core/ListView/ListView.cs | 8 ++++---- src/Controls/src/Core/Menu/MenuBar.cs | 3 ++- src/Controls/src/Core/Menu/MenuBarItem.cs | 3 ++- src/Controls/src/Core/Menu/MenuItem.cs | 4 ++-- src/Controls/src/Core/Page/Page.cs | 4 ++-- .../AndroidSpecific/AppCompat/Application.cs | 7 ++++--- .../PlatformConfiguration/WindowsSpecific/TabbedPage.cs | 3 ++- .../Core/PlatformConfiguration/iOSSpecific/ListView.cs | 3 ++- .../PlatformConfiguration/iOSSpecific/NavigationPage.cs | 5 +++-- .../src/Core/PlatformConfiguration/iOSSpecific/Page.cs | 3 ++- .../Core/PlatformConfiguration/iOSSpecific/ScrollView.cs | 3 ++- .../PlatformConfiguration/iOSSpecific/VisualElement.cs | 3 ++- src/Controls/src/Core/RadioButton/RadioButton.cs | 2 +- src/Controls/src/Core/RefreshView/RefreshView.cs | 4 ++-- src/Controls/src/Core/Shapes/ArcSegment.cs | 3 ++- src/Controls/src/Core/Shapes/PathFigure.cs | 5 +++-- src/Controls/src/Core/Shell/BackButtonBehavior.cs | 5 +++-- src/Controls/src/Core/Shell/BaseShellItem.cs | 6 +++--- src/Controls/src/Core/Shell/SearchHandler.cs | 6 +++--- src/Controls/src/Core/Shell/Shell.cs | 2 +- src/Controls/src/Core/StateTrigger.cs | 3 ++- src/Controls/src/Core/SwipeView/SwipeItem.cs | 3 ++- src/Controls/src/Core/Switch/Switch.cs | 3 ++- src/Controls/src/Core/TabbedPage/TabbedPage.Tizen.cs | 2 +- src/Controls/src/Core/TableView/TableView.cs | 2 +- src/Controls/src/Core/UriImageSource.cs | 3 ++- src/Controls/src/Core/VisualElement/VisualElement.cs | 6 +++--- 46 files changed, 97 insertions(+), 71 deletions(-) diff --git a/src/Controls/src/Core/AppLinkEntry.cs b/src/Controls/src/Core/AppLinkEntry.cs index ee0eee07284f..b748460c20e2 100644 --- a/src/Controls/src/Core/AppLinkEntry.cs +++ b/src/Controls/src/Core/AppLinkEntry.cs @@ -1,6 +1,7 @@ #nullable disable using System; using System.Collections.Generic; +using Microsoft.Maui.Controls.Internals; namespace Microsoft.Maui.Controls { @@ -28,7 +29,7 @@ public AppLinkEntry() public static readonly BindableProperty AppLinkUriProperty = BindableProperty.Create(nameof(AppLinkUri), typeof(Uri), typeof(AppLinkEntry), null); /// Bindable property for . - public static readonly BindableProperty IsLinkActiveProperty = BindableProperty.Create(nameof(IsLinkActive), typeof(bool), typeof(AppLinkEntry), false); + public static readonly BindableProperty IsLinkActiveProperty = BindableProperty.Create(nameof(IsLinkActive), typeof(bool), typeof(AppLinkEntry), BooleanBoxes.FalseBox); /// Gets or sets an application-specific URI that uniquely describes content within an app. This is a bindable property. public Uri AppLinkUri diff --git a/src/Controls/src/Core/Cells/Cell.cs b/src/Controls/src/Core/Cells/Cell.cs index 683c8603ece8..d03c10f5bde6 100644 --- a/src/Controls/src/Core/Cells/Cell.cs +++ b/src/Controls/src/Core/Cells/Cell.cs @@ -16,7 +16,7 @@ public abstract class Cell : Element, ICellController, IFlowDirectionController, /// The default height of cells. public const int DefaultCellHeight = 40; /// Bindable property for . - public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create(nameof(IsEnabled), typeof(bool), typeof(Cell), true, propertyChanged: OnIsEnabledPropertyChanged); + public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create(nameof(IsEnabled), typeof(bool), typeof(Cell), BooleanBoxes.TrueBox, propertyChanged: OnIsEnabledPropertyChanged); ObservableCollection _contextActions; List _currentContextActions; diff --git a/src/Controls/src/Core/Cells/SwitchCell.cs b/src/Controls/src/Core/Cells/SwitchCell.cs index 0e2845b43871..7eb0df884874 100644 --- a/src/Controls/src/Core/Cells/SwitchCell.cs +++ b/src/Controls/src/Core/Cells/SwitchCell.cs @@ -1,5 +1,6 @@ #nullable disable using System; +using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Graphics; namespace Microsoft.Maui.Controls @@ -9,7 +10,7 @@ namespace Microsoft.Maui.Controls public class SwitchCell : Cell { /// Bindable property for . - public static readonly BindableProperty OnProperty = BindableProperty.Create(nameof(On), typeof(bool), typeof(SwitchCell), false, propertyChanged: (obj, oldValue, newValue) => + public static readonly BindableProperty OnProperty = BindableProperty.Create(nameof(On), typeof(bool), typeof(SwitchCell), BooleanBoxes.FalseBox, propertyChanged: (obj, oldValue, newValue) => { var switchCell = (SwitchCell)obj; switchCell.OnChanged?.Invoke(obj, new ToggledEventArgs((bool)newValue)); diff --git a/src/Controls/src/Core/ContentPage/ContentPage.cs b/src/Controls/src/Core/ContentPage/ContentPage.cs index c34fa417c3d3..50a8f6367d7c 100644 --- a/src/Controls/src/Core/ContentPage/ContentPage.cs +++ b/src/Controls/src/Core/ContentPage/ContentPage.cs @@ -3,6 +3,7 @@ using System; using System.Diagnostics; +using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Graphics; using Microsoft.Maui.HotReload; using Microsoft.Maui.Layouts; @@ -27,7 +28,7 @@ public View Content /// Bindable property for . public static readonly BindableProperty HideSoftInputOnTappedProperty - = BindableProperty.Create(nameof(HideSoftInputOnTapped), typeof(bool), typeof(ContentPage), false); + = BindableProperty.Create(nameof(HideSoftInputOnTapped), typeof(bool), typeof(ContentPage), BooleanBoxes.FalseBox); /// Bindable property for . public static readonly BindableProperty SafeAreaEdgesProperty = SafeAreaElement.SafeAreaEdgesProperty; diff --git a/src/Controls/src/Core/DragAndDrop/DragGestureRecognizer.cs b/src/Controls/src/Core/DragAndDrop/DragGestureRecognizer.cs index 77d25490a2e9..657724952931 100644 --- a/src/Controls/src/Core/DragAndDrop/DragGestureRecognizer.cs +++ b/src/Controls/src/Core/DragAndDrop/DragGestureRecognizer.cs @@ -1,6 +1,7 @@ using System; -using System.Windows.Input; +using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Graphics; +using System.Windows.Input; namespace Microsoft.Maui.Controls { @@ -11,7 +12,7 @@ namespace Microsoft.Maui.Controls public class DragGestureRecognizer : GestureRecognizer { /// Bindable property for . - public static readonly BindableProperty CanDragProperty = BindableProperty.Create(nameof(CanDrag), typeof(bool), typeof(DragGestureRecognizer), true); + public static readonly BindableProperty CanDragProperty = BindableProperty.Create(nameof(CanDrag), typeof(bool), typeof(DragGestureRecognizer), BooleanBoxes.TrueBox); /// Bindable property for . public static readonly BindableProperty DropCompletedCommandProperty = BindableProperty.Create(nameof(DropCompletedCommand), typeof(ICommand), typeof(DragGestureRecognizer), null); diff --git a/src/Controls/src/Core/DragAndDrop/DropGestureRecognizer.cs b/src/Controls/src/Core/DragAndDrop/DropGestureRecognizer.cs index 37abd343c747..de5f32daccfa 100644 --- a/src/Controls/src/Core/DragAndDrop/DropGestureRecognizer.cs +++ b/src/Controls/src/Core/DragAndDrop/DropGestureRecognizer.cs @@ -5,6 +5,7 @@ using System.Text; using System.Threading.Tasks; using System.Windows.Input; +using Microsoft.Maui.Controls.Internals; namespace Microsoft.Maui.Controls { @@ -14,7 +15,7 @@ namespace Microsoft.Maui.Controls public class DropGestureRecognizer : GestureRecognizer { /// Bindable property for . - public static readonly BindableProperty AllowDropProperty = BindableProperty.Create(nameof(AllowDrop), typeof(bool), typeof(DropGestureRecognizer), true); + public static readonly BindableProperty AllowDropProperty = BindableProperty.Create(nameof(AllowDrop), typeof(bool), typeof(DropGestureRecognizer), BooleanBoxes.TrueBox); /// Bindable property for . public static readonly BindableProperty DragOverCommandProperty = BindableProperty.Create(nameof(DragOverCommand), typeof(ICommand), typeof(DropGestureRecognizer), null); diff --git a/src/Controls/src/Core/Entry/Entry.cs b/src/Controls/src/Core/Entry/Entry.cs index 9681fd5b8ec7..fd55bc9884fd 100644 --- a/src/Controls/src/Core/Entry/Entry.cs +++ b/src/Controls/src/Core/Entry/Entry.cs @@ -35,7 +35,7 @@ public partial class Entry : InputView, ITextAlignmentElement, IEntryController, /// /// Backing store for the property. /// - public static readonly BindableProperty IsPasswordProperty = BindableProperty.Create(nameof(IsPassword), typeof(bool), typeof(Entry), default(bool)); + public static readonly BindableProperty IsPasswordProperty = BindableProperty.Create(nameof(IsPassword), typeof(bool), typeof(Entry), BooleanBoxes.FalseBox); /// public new static readonly BindableProperty TextProperty = InputView.TextProperty; diff --git a/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs b/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs index a9ce94192b13..e490b7441cdc 100644 --- a/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs +++ b/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs @@ -17,10 +17,10 @@ namespace Microsoft.Maui.Controls public partial class FlyoutPage : Page, IFlyoutPageController, IElementConfiguration, IFlyoutView { /// Bindable property for . - public static readonly BindableProperty IsGestureEnabledProperty = BindableProperty.Create(nameof(IsGestureEnabled), typeof(bool), typeof(FlyoutPage), true); + public static readonly BindableProperty IsGestureEnabledProperty = BindableProperty.Create(nameof(IsGestureEnabled), typeof(bool), typeof(FlyoutPage), BooleanBoxes.TrueBox); /// Bindable property for . - public static readonly BindableProperty IsPresentedProperty = BindableProperty.Create(nameof(IsPresented), typeof(bool), typeof(FlyoutPage), default(bool), + public static readonly BindableProperty IsPresentedProperty = BindableProperty.Create(nameof(IsPresented), typeof(bool), typeof(FlyoutPage), BooleanBoxes.FalseBox, propertyChanged: OnIsPresentedPropertyChanged, propertyChanging: OnIsPresentedPropertyChanging, defaultValueCreator: GetDefaultValue); /// Bindable property for . diff --git a/src/Controls/src/Core/FontImageSource.cs b/src/Controls/src/Core/FontImageSource.cs index 9dc302b8aca0..07838598be76 100644 --- a/src/Controls/src/Core/FontImageSource.cs +++ b/src/Controls/src/Core/FontImageSource.cs @@ -1,4 +1,5 @@ #nullable disable +using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Graphics; namespace Microsoft.Maui.Controls @@ -57,7 +58,7 @@ public double Size /// Bindable property for . public static readonly BindableProperty FontAutoScalingEnabledProperty = - BindableProperty.Create(nameof(FontAutoScalingEnabled), typeof(bool), typeof(FontImageSource), false, + BindableProperty.Create(nameof(FontAutoScalingEnabled), typeof(bool), typeof(FontImageSource), BooleanBoxes.FalseBox, propertyChanged: (b, o, n) => ((FontImageSource)b).OnSourceChanged()); public bool FontAutoScalingEnabled diff --git a/src/Controls/src/Core/Frame/Frame.cs b/src/Controls/src/Core/Frame/Frame.cs index a15e72d8bbe1..c32e8393a0d2 100644 --- a/src/Controls/src/Core/Frame/Frame.cs +++ b/src/Controls/src/Core/Frame/Frame.cs @@ -1,5 +1,6 @@ #nullable disable using System; +using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Graphics; using Microsoft.Maui.Layouts; @@ -14,7 +15,7 @@ public partial class Frame : ContentView, IElementConfiguration, IPadding public static readonly BindableProperty BorderColorProperty = BorderElement.BorderColorProperty; /// Bindable property for . - public static readonly BindableProperty HasShadowProperty = BindableProperty.Create(nameof(HasShadow), typeof(bool), typeof(Frame), true); + public static readonly BindableProperty HasShadowProperty = BindableProperty.Create(nameof(HasShadow), typeof(bool), typeof(Frame), BooleanBoxes.TrueBox); /// Bindable property for . public static readonly BindableProperty CornerRadiusProperty = BindableProperty.Create(nameof(CornerRadius), typeof(float), typeof(Frame), -1.0f, diff --git a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellContentItemView.cs b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellContentItemView.cs index 9141ef4ca5fe..3b22385793eb 100644 --- a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellContentItemView.cs +++ b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellContentItemView.cs @@ -8,7 +8,7 @@ namespace Microsoft.Maui.Controls.Platform class ShellContentItemView : Frame #pragma warning restore CS0618 // Type or member is obsolete { - static readonly BindableProperty SelectedStateProperty = BindableProperty.Create(nameof(IsSelected), typeof(bool), typeof(ShellContentItemView), false, propertyChanged: (b, o, n) => ((ShellContentItemView)b).UpdateViewColors()); + static readonly BindableProperty SelectedStateProperty = BindableProperty.Create(nameof(IsSelected), typeof(bool), typeof(ShellContentItemView), BooleanBoxes.FalseBox, propertyChanged: (b, o, n) => ((ShellContentItemView)b).UpdateViewColors()); internal static readonly BindableProperty SelectedTextColorProperty = BindableProperty.Create(nameof(SelectedTextColor), typeof(GColor), typeof(ShellContentItemView), null, propertyChanged: (b, o, n) => ((ShellContentItemView)b).UpdateViewColors()); internal static readonly BindableProperty SelectedBarColorProperty = BindableProperty.Create(nameof(SelectedBarColor), typeof(GColor), typeof(ShellContentItemView), null, propertyChanged: (b, o, n) => ((ShellContentItemView)b).UpdateViewColors()); internal static readonly BindableProperty UnselectedColorProperty = BindableProperty.Create(nameof(UnselectedColor), typeof(GColor), typeof(ShellContentItemView), null, propertyChanged: (b, o, n) => ((ShellContentItemView)b).UpdateViewColors()); diff --git a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellFlyoutItemView.cs b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellFlyoutItemView.cs index cb068265dfd4..c1eb375a090f 100644 --- a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellFlyoutItemView.cs +++ b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellFlyoutItemView.cs @@ -7,7 +7,7 @@ namespace Microsoft.Maui.Controls.Platform class ShellFlyoutItemView : Frame #pragma warning restore CS0618 // Type or member is obsolete { - static readonly BindableProperty SelectedStateProperty = BindableProperty.Create(nameof(IsSelected), typeof(bool), typeof(ShellFlyoutItemView), false, propertyChanged: (b, o, n) => ((ShellFlyoutItemView)b).UpdateSelectedState()); + static readonly BindableProperty SelectedStateProperty = BindableProperty.Create(nameof(IsSelected), typeof(bool), typeof(ShellFlyoutItemView), BooleanBoxes.FalseBox, propertyChanged: (b, o, n) => ((ShellFlyoutItemView)b).UpdateSelectedState()); Grid _grid; diff --git a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellSectionItemView.cs b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellSectionItemView.cs index ec33c2b5d160..310ece04914d 100644 --- a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellSectionItemView.cs +++ b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellSectionItemView.cs @@ -9,7 +9,7 @@ namespace Microsoft.Maui.Controls.Platform class ShellSectionItemView : Frame #pragma warning restore CS0618 // Type or member is obsolete { - static readonly BindableProperty SelectedStateProperty = BindableProperty.Create(nameof(IsSelected), typeof(bool), typeof(ShellSectionItemView), false, propertyChanged: (b, o, n) => ((ShellSectionItemView)b).UpdateViewColors()); + static readonly BindableProperty SelectedStateProperty = BindableProperty.Create(nameof(IsSelected), typeof(bool), typeof(ShellSectionItemView), BooleanBoxes.FalseBox, propertyChanged: (b, o, n) => ((ShellSectionItemView)b).UpdateViewColors()); internal static readonly BindableProperty SelectedColorProperty = BindableProperty.Create(nameof(SelectedColor), typeof(GColor), typeof(ShellSectionItemView), null, propertyChanged: (b, o, n) => ((ShellSectionItemView)b).UpdateViewColors()); internal static readonly BindableProperty UnselectedColorProperty = BindableProperty.Create(nameof(UnselectedColor), typeof(GColor), typeof(ShellSectionItemView), null, propertyChanged: (b, o, n) => ((ShellSectionItemView)b).UpdateViewColors()); diff --git a/src/Controls/src/Core/IndicatorView/IndicatorView.cs b/src/Controls/src/Core/IndicatorView/IndicatorView.cs index 961d99bb11d3..72031ca88acb 100644 --- a/src/Controls/src/Core/IndicatorView/IndicatorView.cs +++ b/src/Controls/src/Core/IndicatorView/IndicatorView.cs @@ -43,7 +43,7 @@ public partial class IndicatorView : TemplatedView, ITemplatedIndicatorView => UpdateIndicatorLayout((IndicatorView)bindable, newValue)); /// Bindable property for . - public static readonly BindableProperty HideSingleProperty = BindableProperty.Create(nameof(HideSingle), typeof(bool), typeof(IndicatorView), true); + public static readonly BindableProperty HideSingleProperty = BindableProperty.Create(nameof(HideSingle), typeof(bool), typeof(IndicatorView), BooleanBoxes.TrueBox); /// Bindable property for . public static readonly BindableProperty IndicatorColorProperty = BindableProperty.Create(nameof(IndicatorColor), typeof(Color), typeof(IndicatorView), Colors.LightGrey); diff --git a/src/Controls/src/Core/InputView/InputView.cs b/src/Controls/src/Core/InputView/InputView.cs index 51cd1ff9c711..cccfb906fcba 100644 --- a/src/Controls/src/Core/InputView/InputView.cs +++ b/src/Controls/src/Core/InputView/InputView.cs @@ -22,16 +22,16 @@ public partial class InputView : View, IPlaceholderElement, ITextElement, ITextI coerceValue: (o, v) => (Keyboard)v ?? Keyboard.Default); /// Bindable property for . - public static readonly BindableProperty IsSpellCheckEnabledProperty = BindableProperty.Create(nameof(IsSpellCheckEnabled), typeof(bool), typeof(InputView), true); + public static readonly BindableProperty IsSpellCheckEnabledProperty = BindableProperty.Create(nameof(IsSpellCheckEnabled), typeof(bool), typeof(InputView), BooleanBoxes.TrueBox); /// Bindable property for . - public static readonly BindableProperty IsTextPredictionEnabledProperty = BindableProperty.Create(nameof(IsTextPredictionEnabled), typeof(bool), typeof(InputView), true); + public static readonly BindableProperty IsTextPredictionEnabledProperty = BindableProperty.Create(nameof(IsTextPredictionEnabled), typeof(bool), typeof(InputView), BooleanBoxes.TrueBox); /// Bindable property for . public static readonly BindableProperty MaxLengthProperty = BindableProperty.Create(nameof(MaxLength), typeof(int), typeof(InputView), int.MaxValue); /// Bindable property for . - public static readonly BindableProperty IsReadOnlyProperty = BindableProperty.Create(nameof(IsReadOnly), typeof(bool), typeof(InputView), false); + public static readonly BindableProperty IsReadOnlyProperty = BindableProperty.Create(nameof(IsReadOnly), typeof(bool), typeof(InputView), BooleanBoxes.FalseBox); /// Bindable property for . public static readonly BindableProperty PlaceholderProperty = PlaceholderElement.PlaceholderProperty; diff --git a/src/Controls/src/Core/Items/CarouselView.cs b/src/Controls/src/Core/Items/CarouselView.cs index 2039736d9304..81381d872dbd 100644 --- a/src/Controls/src/Core/Items/CarouselView.cs +++ b/src/Controls/src/Core/Items/CarouselView.cs @@ -47,7 +47,7 @@ public class CarouselView : ItemsView public const string DefaultItemVisualState = "DefaultItem"; /// Bindable property for . - public static readonly BindableProperty LoopProperty = BindableProperty.Create(nameof(Loop), typeof(bool), typeof(CarouselView), true, BindingMode.OneTime); + public static readonly BindableProperty LoopProperty = BindableProperty.Create(nameof(Loop), typeof(bool), typeof(CarouselView), BooleanBoxes.TrueBox, BindingMode.OneTime); /// /// Gets or sets a value indicating whether the carousel loops back to the first item after reaching the last item. @@ -111,7 +111,7 @@ public Thickness PeekAreaInsets /// Bindable property for . public static readonly BindableProperty IsBounceEnabledProperty = - BindableProperty.Create(nameof(IsBounceEnabled), typeof(bool), typeof(CarouselView), true); + BindableProperty.Create(nameof(IsBounceEnabled), typeof(bool), typeof(CarouselView), BooleanBoxes.TrueBox); /// /// Gets or sets a value indicating whether bounce effects are enabled when scrolling reaches the end of the carousel. @@ -129,7 +129,7 @@ public bool IsBounceEnabled /// Bindable property for . public static readonly BindableProperty IsSwipeEnabledProperty = - BindableProperty.Create(nameof(IsSwipeEnabled), typeof(bool), typeof(CarouselView), true); + BindableProperty.Create(nameof(IsSwipeEnabled), typeof(bool), typeof(CarouselView), BooleanBoxes.TrueBox); /// /// Gets or sets a value indicating whether swipe gestures are enabled for navigation. @@ -147,7 +147,7 @@ public bool IsSwipeEnabled /// Bindable property for . public static readonly BindableProperty IsScrollAnimatedProperty = - BindableProperty.Create(nameof(IsScrollAnimated), typeof(bool), typeof(CarouselView), true); + BindableProperty.Create(nameof(IsScrollAnimated), typeof(bool), typeof(CarouselView), BooleanBoxes.TrueBox); /// /// Gets or sets a value indicating whether scrolling between items is animated. diff --git a/src/Controls/src/Core/Items/GroupableItemsView.cs b/src/Controls/src/Core/Items/GroupableItemsView.cs index 941b4052069a..8cd6bce89c1f 100644 --- a/src/Controls/src/Core/Items/GroupableItemsView.cs +++ b/src/Controls/src/Core/Items/GroupableItemsView.cs @@ -1,4 +1,5 @@ #nullable disable +using Microsoft.Maui.Controls.Internals; namespace Microsoft.Maui.Controls { /// @@ -13,7 +14,7 @@ public class GroupableItemsView : SelectableItemsView { /// Bindable property for . public static readonly BindableProperty IsGroupedProperty = - BindableProperty.Create(nameof(IsGrouped), typeof(bool), typeof(GroupableItemsView), false); + BindableProperty.Create(nameof(IsGrouped), typeof(bool), typeof(GroupableItemsView), BooleanBoxes.FalseBox); /// /// Gets or sets a value indicating whether items should be displayed in groups. diff --git a/src/Controls/src/Core/Items/ReorderableItemsView.cs b/src/Controls/src/Core/Items/ReorderableItemsView.cs index 7f3c63454cd2..ff2722bb7510 100644 --- a/src/Controls/src/Core/Items/ReorderableItemsView.cs +++ b/src/Controls/src/Core/Items/ReorderableItemsView.cs @@ -1,6 +1,7 @@ #nullable disable using System; using System.ComponentModel; +using Microsoft.Maui.Controls.Internals; namespace Microsoft.Maui.Controls { @@ -24,7 +25,7 @@ public class ReorderableItemsView : GroupableItemsView public event EventHandler ReorderCompleted; /// Bindable property for . - public static readonly BindableProperty CanMixGroupsProperty = BindableProperty.Create(nameof(CanMixGroups), typeof(bool), typeof(ReorderableItemsView), false); + public static readonly BindableProperty CanMixGroupsProperty = BindableProperty.Create(nameof(CanMixGroups), typeof(bool), typeof(ReorderableItemsView), BooleanBoxes.FalseBox); /// /// Gets or sets a value indicating whether items from different groups can be mixed together during reordering. @@ -42,7 +43,7 @@ public bool CanMixGroups } /// Bindable property for . - public static readonly BindableProperty CanReorderItemsProperty = BindableProperty.Create(nameof(CanReorderItems), typeof(bool), typeof(ReorderableItemsView), false); + public static readonly BindableProperty CanReorderItemsProperty = BindableProperty.Create(nameof(CanReorderItems), typeof(bool), typeof(ReorderableItemsView), BooleanBoxes.FalseBox); /// /// Gets or sets a value indicating whether items in the collection can be reordered by the user. diff --git a/src/Controls/src/Core/Layout/Layout.cs b/src/Controls/src/Core/Layout/Layout.cs index 7f7d63261256..89ad7c3d0a1d 100644 --- a/src/Controls/src/Core/Layout/Layout.cs +++ b/src/Controls/src/Core/Layout/Layout.cs @@ -6,6 +6,7 @@ using System.Linq; using Microsoft.Extensions.DependencyInjection; using Microsoft.Maui; +using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Controls.Xaml.Diagnostics; using Microsoft.Maui.Graphics; using Microsoft.Maui.Layouts; @@ -86,7 +87,7 @@ public IView this[int index] /// Bindable property for . public static readonly BindableProperty IsClippedToBoundsProperty = - BindableProperty.Create(nameof(IsClippedToBounds), typeof(bool), typeof(Layout), false, + BindableProperty.Create(nameof(IsClippedToBounds), typeof(bool), typeof(Layout), BooleanBoxes.FalseBox, propertyChanged: IsClippedToBoundsPropertyChanged); /// diff --git a/src/Controls/src/Core/ListView/ListView.cs b/src/Controls/src/Core/ListView/ListView.cs index f2b076d5802d..922b01cf6f60 100644 --- a/src/Controls/src/Core/ListView/ListView.cs +++ b/src/Controls/src/Core/ListView/ListView.cs @@ -26,10 +26,10 @@ public class ListView : ItemsView, IListViewController, IElementConfigurat IReadOnlyList IVisualTreeElement.GetVisualChildren() => _visualChildren; /// Bindable property for . - public static readonly BindableProperty IsPullToRefreshEnabledProperty = BindableProperty.Create(nameof(IsPullToRefreshEnabled), typeof(bool), typeof(ListView), false); + public static readonly BindableProperty IsPullToRefreshEnabledProperty = BindableProperty.Create(nameof(IsPullToRefreshEnabled), typeof(bool), typeof(ListView), BooleanBoxes.FalseBox); /// Bindable property for . - public static readonly BindableProperty IsRefreshingProperty = BindableProperty.Create(nameof(IsRefreshing), typeof(bool), typeof(ListView), false, BindingMode.TwoWay); + public static readonly BindableProperty IsRefreshingProperty = BindableProperty.Create(nameof(IsRefreshing), typeof(bool), typeof(ListView), BooleanBoxes.FalseBox, BindingMode.TwoWay); /// Bindable property for . public static readonly BindableProperty RefreshCommandProperty = BindableProperty.Create(nameof(RefreshCommand), typeof(ICommand), typeof(ListView), null, propertyChanged: OnRefreshCommandChanged); @@ -56,7 +56,7 @@ public class ListView : ItemsView, IListViewController, IElementConfigurat public static readonly BindableProperty SelectionModeProperty = BindableProperty.Create(nameof(SelectionMode), typeof(ListViewSelectionMode), typeof(ListView), ListViewSelectionMode.Single); /// Bindable property for . - public static readonly BindableProperty HasUnevenRowsProperty = BindableProperty.Create(nameof(HasUnevenRows), typeof(bool), typeof(ListView), false); + public static readonly BindableProperty HasUnevenRowsProperty = BindableProperty.Create(nameof(HasUnevenRows), typeof(bool), typeof(ListView), BooleanBoxes.FalseBox); /// Bindable property for . public static readonly BindableProperty RowHeightProperty = BindableProperty.Create(nameof(RowHeight), typeof(int), typeof(ListView), -1); @@ -66,7 +66,7 @@ public class ListView : ItemsView, IListViewController, IElementConfigurat propertyChanged: OnGroupHeaderTemplateChanged); /// Bindable property for . - public static readonly BindableProperty IsGroupingEnabledProperty = BindableProperty.Create(nameof(IsGroupingEnabled), typeof(bool), typeof(ListView), false); + public static readonly BindableProperty IsGroupingEnabledProperty = BindableProperty.Create(nameof(IsGroupingEnabled), typeof(bool), typeof(ListView), BooleanBoxes.FalseBox); /// Bindable property for . public static readonly BindableProperty SeparatorVisibilityProperty = BindableProperty.Create(nameof(SeparatorVisibility), typeof(SeparatorVisibility), typeof(ListView), SeparatorVisibility.Default); diff --git a/src/Controls/src/Core/Menu/MenuBar.cs b/src/Controls/src/Core/Menu/MenuBar.cs index efea6758ea8e..5da4d714ce37 100644 --- a/src/Controls/src/Core/Menu/MenuBar.cs +++ b/src/Controls/src/Core/Menu/MenuBar.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; +using Microsoft.Maui.Controls.Internals; namespace Microsoft.Maui.Controls { @@ -10,7 +11,7 @@ public partial class MenuBar : Element, IMenuBar { /// Bindable property for . public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create(nameof(IsEnabled), typeof(bool), - typeof(MenuBar), true); + typeof(MenuBar), BooleanBoxes.TrueBox); public bool IsEnabled { diff --git a/src/Controls/src/Core/Menu/MenuBarItem.cs b/src/Controls/src/Core/Menu/MenuBarItem.cs index 79fbf10b92a6..b1dcbbd0f6fb 100644 --- a/src/Controls/src/Core/Menu/MenuBarItem.cs +++ b/src/Controls/src/Core/Menu/MenuBarItem.cs @@ -3,6 +3,7 @@ using System.Collections; using System.Collections.Generic; using System.Collections.ObjectModel; +using Microsoft.Maui.Controls.Internals; namespace Microsoft.Maui.Controls { @@ -14,7 +15,7 @@ public partial class MenuBarItem : BaseMenuItem, IMenuBarItem /// Bindable property for . public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create(nameof(IsEnabled), typeof(bool), - typeof(MenuBarItem), true); + typeof(MenuBarItem), BooleanBoxes.TrueBox); static readonly BindableProperty PriorityProperty = BindableProperty.Create(nameof(Priority), typeof(int), typeof(ToolbarItem), 0); public MenuBarItem() diff --git a/src/Controls/src/Core/Menu/MenuItem.cs b/src/Controls/src/Core/Menu/MenuItem.cs index 77b338b319d4..f608a3338622 100644 --- a/src/Controls/src/Core/Menu/MenuItem.cs +++ b/src/Controls/src/Core/Menu/MenuItem.cs @@ -34,7 +34,7 @@ static MenuItem() } /// Bindable property for . - public static readonly BindableProperty IsDestructiveProperty = BindableProperty.Create(nameof(IsDestructive), typeof(bool), typeof(MenuItem), false); + public static readonly BindableProperty IsDestructiveProperty = BindableProperty.Create(nameof(IsDestructive), typeof(bool), typeof(MenuItem), BooleanBoxes.FalseBox); /// Bindable property for . public static readonly BindableProperty IconImageSourceProperty = BindableProperty.Create(nameof(IconImageSource), typeof(ImageSource), typeof(MenuItem), default(ImageSource), @@ -47,7 +47,7 @@ static MenuItem() /// Bindable property for . public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create( - nameof(IsEnabled), typeof(bool), typeof(MenuItem), true, + nameof(IsEnabled), typeof(bool), typeof(MenuItem), BooleanBoxes.TrueBox, propertyChanged: OnIsEnabledPropertyChanged, coerceValue: CoerceIsEnabledProperty); /// Bindable property for . diff --git a/src/Controls/src/Core/Page/Page.cs b/src/Controls/src/Core/Page/Page.cs index ea46e5b0060d..24d1fcfeac84 100644 --- a/src/Controls/src/Core/Page/Page.cs +++ b/src/Controls/src/Core/Page/Page.cs @@ -50,14 +50,14 @@ public partial class Page : VisualElement, ILayout, IPageController, IElementCon /// For internal use only. This API can be changed or removed without notice at any time. public const string ActionSheetSignalName = "Microsoft.Maui.Controls.ShowActionSheet"; - internal static readonly BindableProperty IgnoresContainerAreaProperty = BindableProperty.Create(nameof(IgnoresContainerArea), typeof(bool), typeof(Page), false); + internal static readonly BindableProperty IgnoresContainerAreaProperty = BindableProperty.Create(nameof(IgnoresContainerArea), typeof(bool), typeof(Page), BooleanBoxes.FalseBox); /// Bindable property for . public static readonly BindableProperty BackgroundImageSourceProperty = BindableProperty.Create(nameof(BackgroundImageSource), typeof(ImageSource), typeof(Page), default(ImageSource)); /// Bindable property for . [Obsolete("Page.IsBusy has been deprecated and will be removed in .NET 11")] - public static readonly BindableProperty IsBusyProperty = BindableProperty.Create(nameof(IsBusy), typeof(bool), typeof(Page), false, propertyChanged: (bo, o, n) => ((Page)bo).OnPageBusyChanged()); + public static readonly BindableProperty IsBusyProperty = BindableProperty.Create(nameof(IsBusy), typeof(bool), typeof(Page), BooleanBoxes.FalseBox, propertyChanged: (bo, o, n) => ((Page)bo).OnPageBusyChanged()); /// Bindable property for . public static readonly BindableProperty PaddingProperty = PaddingElement.PaddingProperty; diff --git a/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/AppCompat/Application.cs b/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/AppCompat/Application.cs index 57a9a1b12b24..a56a2496a742 100644 --- a/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/AppCompat/Application.cs +++ b/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/AppCompat/Application.cs @@ -1,13 +1,14 @@ #nullable disable namespace Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific.AppCompat { + using Microsoft.Maui.Controls.Internals; using FormsElement = Maui.Controls.Application; /// AppCompat application instance on Android. public static class Application { /// Bindable property for . - public static readonly BindableProperty SendDisappearingEventOnPauseProperty = BindableProperty.Create(nameof(SendDisappearingEventOnPause), typeof(bool), typeof(Application), true); + public static readonly BindableProperty SendDisappearingEventOnPauseProperty = BindableProperty.Create(nameof(SendDisappearingEventOnPause), typeof(bool), typeof(Application), BooleanBoxes.TrueBox); /// Returns a Boolean value that controls whether the disappearing event is sent when the application is paused. /// The platform specific element on which to perform the operation. @@ -43,7 +44,7 @@ public static IPlatformElementConfiguration SendDisappear } /// Bindable property for . - public static readonly BindableProperty SendAppearingEventOnResumeProperty = BindableProperty.Create(nameof(SendAppearingEventOnResume), typeof(bool), typeof(Application), true); + public static readonly BindableProperty SendAppearingEventOnResumeProperty = BindableProperty.Create(nameof(SendAppearingEventOnResume), typeof(bool), typeof(Application), BooleanBoxes.TrueBox); /// Returns a Boolean value that controls whether the appearing event is sent when the application resumes. /// The platform specific element on which to perform the operation. @@ -79,7 +80,7 @@ public static IPlatformElementConfiguration SendAppearing } /// Bindable property for . - public static readonly BindableProperty ShouldPreserveKeyboardOnResumeProperty = BindableProperty.Create(nameof(ShouldPreserveKeyboardOnResume), typeof(bool), typeof(Application), false); + public static readonly BindableProperty ShouldPreserveKeyboardOnResumeProperty = BindableProperty.Create(nameof(ShouldPreserveKeyboardOnResume), typeof(bool), typeof(Application), BooleanBoxes.FalseBox); /// Returns a Boolean value that controls whether the keyboard state should be preserved when the application resumes. /// The platform specific element on which to perform the operation. diff --git a/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/TabbedPage.cs b/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/TabbedPage.cs index 2a919ddce020..6e210e85c4a5 100644 --- a/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/TabbedPage.cs +++ b/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/TabbedPage.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Generic; using System.Text; +using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Graphics; namespace Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific @@ -13,7 +14,7 @@ public static class TabbedPage { /// Bindable property for attached property HeaderIconsEnabled. public static readonly BindableProperty HeaderIconsEnabledProperty = - BindableProperty.Create(nameof(HeaderIconsEnabledProperty), typeof(bool), typeof(TabbedPage), true); + BindableProperty.Create(nameof(HeaderIconsEnabledProperty), typeof(bool), typeof(TabbedPage), BooleanBoxes.TrueBox); /// Bindable property for attached property HeaderIconsSize. public static readonly BindableProperty HeaderIconsSizeProperty = diff --git a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/ListView.cs b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/ListView.cs index d6b4380f0298..91cca1b1a61f 100644 --- a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/ListView.cs +++ b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/ListView.cs @@ -2,6 +2,7 @@ namespace Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific { using System; + using Microsoft.Maui.Controls.Internals; using FormsElement = Maui.Controls.ListView; /// Provides access to the separator style for list views on the iOS platform. [Obsolete("With the deprecation of ListView, this class is obsolete. Please use CollectionView instead.")] @@ -109,7 +110,7 @@ public static IPlatformElementConfiguration SetGroupHeaderSty /// Bindable property for . [Obsolete("With the deprecation of ListView, this property is obsolete. Please use CollectionView instead.")] - public static readonly BindableProperty RowAnimationsEnabledProperty = BindableProperty.Create(nameof(RowAnimationsEnabled), typeof(bool), typeof(ListView), true); + public static readonly BindableProperty RowAnimationsEnabledProperty = BindableProperty.Create(nameof(RowAnimationsEnabled), typeof(bool), typeof(ListView), BooleanBoxes.TrueBox); /// The element parameter. [Obsolete("With the deprecation of ListView, this property is obsolete. Please use CollectionView instead.")] diff --git a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/NavigationPage.cs b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/NavigationPage.cs index d646736085ed..c4f585afa574 100644 --- a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/NavigationPage.cs +++ b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/NavigationPage.cs @@ -3,6 +3,7 @@ namespace Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific { using System; + using Microsoft.Maui.Controls.Internals; using FormsElement = Maui.Controls.NavigationPage; /// The navigation page instance that Microsoft.Maui.Controls created on the iOS platform. @@ -119,7 +120,7 @@ public static IPlatformElementConfiguration SetStatusBarTextC #region PrefersLargeTitles /// Bindable property for . - public static readonly BindableProperty PrefersLargeTitlesProperty = BindableProperty.Create(nameof(PrefersLargeTitles), typeof(bool), typeof(Page), false); + public static readonly BindableProperty PrefersLargeTitlesProperty = BindableProperty.Create(nameof(PrefersLargeTitles), typeof(bool), typeof(Page), BooleanBoxes.FalseBox); /// Returns the large title preference of . /// The element whose large title preference to get. @@ -158,7 +159,7 @@ public static bool PrefersLargeTitles(this IPlatformElementConfigurationBindable property for . - public static readonly BindableProperty HideNavigationBarSeparatorProperty = BindableProperty.Create(nameof(HideNavigationBarSeparator), typeof(bool), typeof(Page), false); + public static readonly BindableProperty HideNavigationBarSeparatorProperty = BindableProperty.Create(nameof(HideNavigationBarSeparator), typeof(bool), typeof(Page), BooleanBoxes.FalseBox); /// Returns if the separator is hidden. Otherwise, returns . /// The element for which to return whether the navigation bar separator is hidden. diff --git a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Page.cs b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Page.cs index e0fa4a23a2eb..14b55136a102 100644 --- a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Page.cs +++ b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Page.cs @@ -1,5 +1,6 @@ #nullable disable using System.ComponentModel; +using Microsoft.Maui.Controls.Internals; namespace Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific { @@ -418,7 +419,7 @@ static void SetModalPopoverRect(BindableObject element, System.Drawing.Rectangle /// Bindable property for . public static readonly BindableProperty PrefersHomeIndicatorAutoHiddenProperty = - BindableProperty.Create(nameof(PrefersHomeIndicatorAutoHidden), typeof(bool), typeof(Page), false); + BindableProperty.Create(nameof(PrefersHomeIndicatorAutoHidden), typeof(bool), typeof(Page), BooleanBoxes.FalseBox); /// /// Gets a value that indicates whether the visual indicator should hide upon returning to the home screen. diff --git a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/ScrollView.cs b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/ScrollView.cs index 1541aec56719..5966b8c12dc5 100644 --- a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/ScrollView.cs +++ b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/ScrollView.cs @@ -1,13 +1,14 @@ #nullable disable namespace Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific { + using Microsoft.Maui.Controls.Internals; using FormsElement = Maui.Controls.ScrollView; /// The scroll view instance that Microsoft.Maui.Controls created on the iOS platform. public static class ScrollView { /// Bindable property for . - public static readonly BindableProperty ShouldDelayContentTouchesProperty = BindableProperty.Create(nameof(ShouldDelayContentTouches), typeof(bool), typeof(ScrollView), true); + public static readonly BindableProperty ShouldDelayContentTouchesProperty = BindableProperty.Create(nameof(ShouldDelayContentTouches), typeof(bool), typeof(ScrollView), BooleanBoxes.TrueBox); /// Returns a Boolean value that tells whether iOS will wait to determine if a touch is intended as a scroll, or scroll immediately. /// The platform specific element on which to perform the operation. diff --git a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/VisualElement.cs b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/VisualElement.cs index 6fa329ef1515..fb4b31b3277f 100644 --- a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/VisualElement.cs +++ b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/VisualElement.cs @@ -3,6 +3,7 @@ namespace Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific { using System; + using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Graphics; using FormsElement = Maui.Controls.VisualElement; @@ -377,7 +378,7 @@ public static IPlatformElementConfiguration SetIsLegacyColorM #endregion /// Bindable property for . - public static readonly BindableProperty CanBecomeFirstResponderProperty = BindableProperty.Create(nameof(CanBecomeFirstResponder), typeof(bool), typeof(VisualElement), false); + public static readonly BindableProperty CanBecomeFirstResponderProperty = BindableProperty.Create(nameof(CanBecomeFirstResponder), typeof(bool), typeof(VisualElement), BooleanBoxes.FalseBox); /// /// Gets whether this element can become the first responder to touch events, rather than the page containing the element. diff --git a/src/Controls/src/Core/RadioButton/RadioButton.cs b/src/Controls/src/Core/RadioButton/RadioButton.cs index 9a21f28fd29c..e4e3398dcdaa 100644 --- a/src/Controls/src/Core/RadioButton/RadioButton.cs +++ b/src/Controls/src/Core/RadioButton/RadioButton.cs @@ -89,7 +89,7 @@ public partial class RadioButton : TemplatedView, IElementConfigurationBindable property for . This is a bindable property. public static readonly BindableProperty IsCheckedProperty = BindableProperty.Create( - nameof(IsChecked), typeof(bool), typeof(RadioButton), false, + nameof(IsChecked), typeof(bool), typeof(RadioButton), BooleanBoxes.FalseBox, propertyChanged: (b, o, n) => ((RadioButton)b).OnIsCheckedPropertyChanged((bool)n), defaultBindingMode: BindingMode.TwoWay); diff --git a/src/Controls/src/Core/RefreshView/RefreshView.cs b/src/Controls/src/Core/RefreshView/RefreshView.cs index 509cec88c683..3f2a1bab43fa 100644 --- a/src/Controls/src/Core/RefreshView/RefreshView.cs +++ b/src/Controls/src/Core/RefreshView/RefreshView.cs @@ -34,7 +34,7 @@ public RefreshView() /// Bindable property for . public static readonly BindableProperty IsRefreshingProperty = - BindableProperty.Create(nameof(IsRefreshing), typeof(bool), typeof(RefreshView), false, BindingMode.TwoWay, coerceValue: OnIsRefreshingPropertyCoerced, propertyChanged: OnIsRefreshingPropertyChanged); + BindableProperty.Create(nameof(IsRefreshing), typeof(bool), typeof(RefreshView), BooleanBoxes.FalseBox, BindingMode.TwoWay, coerceValue: OnIsRefreshingPropertyCoerced, propertyChanged: OnIsRefreshingPropertyChanged); static void OnIsRefreshingPropertyChanged(BindableObject bindable, object oldValue, object newValue) { @@ -123,7 +123,7 @@ public Color RefreshColor /// Bindable property for . public static readonly BindableProperty IsRefreshEnabledProperty = - BindableProperty.Create(nameof(IsRefreshEnabled), typeof(bool), typeof(RefreshView), true, + BindableProperty.Create(nameof(IsRefreshEnabled), typeof(bool), typeof(RefreshView), BooleanBoxes.TrueBox, propertyChanged: OnIsRefreshEnabledPropertyChanged, coerceValue: CoerceIsRefreshEnabledProperty); bool _isRefreshEnabledExplicit = (bool)IsRefreshEnabledProperty.DefaultValue; diff --git a/src/Controls/src/Core/Shapes/ArcSegment.cs b/src/Controls/src/Core/Shapes/ArcSegment.cs index 8e48f810ac7e..9ad77d58cdde 100644 --- a/src/Controls/src/Core/Shapes/ArcSegment.cs +++ b/src/Controls/src/Core/Shapes/ArcSegment.cs @@ -1,4 +1,5 @@ #nullable disable +using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Graphics; using Microsoft.Maui.Graphics.Converters; @@ -52,7 +53,7 @@ public ArcSegment(Point point, Size size, double rotationAngle, SweepDirection s /// Bindable property for . public static readonly BindableProperty IsLargeArcProperty = - BindableProperty.Create(nameof(IsLargeArc), typeof(bool), typeof(ArcSegment), false); + BindableProperty.Create(nameof(IsLargeArc), typeof(bool), typeof(ArcSegment), BooleanBoxes.FalseBox); /// /// Gets or sets the endpoint of the arc. This is a bindable property. diff --git a/src/Controls/src/Core/Shapes/PathFigure.cs b/src/Controls/src/Core/Shapes/PathFigure.cs index 9c71d665d218..c2ca9626b263 100644 --- a/src/Controls/src/Core/Shapes/PathFigure.cs +++ b/src/Controls/src/Core/Shapes/PathFigure.cs @@ -2,6 +2,7 @@ using System; using System.Collections.Specialized; using System.ComponentModel; +using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Graphics; namespace Microsoft.Maui.Controls.Shapes @@ -36,11 +37,11 @@ static void OnPathSegmentCollectionChanged(BindableObject bindable, object oldVa /// Bindable property for . public static readonly BindableProperty IsClosedProperty = - BindableProperty.Create(nameof(IsClosed), typeof(bool), typeof(PathFigure), false); + BindableProperty.Create(nameof(IsClosed), typeof(bool), typeof(PathFigure), BooleanBoxes.FalseBox); /// Bindable property for . public static readonly BindableProperty IsFilledProperty = - BindableProperty.Create(nameof(IsFilled), typeof(bool), typeof(PathFigure), true); + BindableProperty.Create(nameof(IsFilled), typeof(bool), typeof(PathFigure), BooleanBoxes.TrueBox); /// /// Gets or sets the collection of path segments that define this figure. This is a bindable property. diff --git a/src/Controls/src/Core/Shell/BackButtonBehavior.cs b/src/Controls/src/Core/Shell/BackButtonBehavior.cs index 5e9b062fc730..e8da835d7573 100644 --- a/src/Controls/src/Core/Shell/BackButtonBehavior.cs +++ b/src/Controls/src/Core/Shell/BackButtonBehavior.cs @@ -1,6 +1,7 @@ #nullable disable using System; using System.Windows.Input; +using Microsoft.Maui.Controls.Internals; namespace Microsoft.Maui.Controls { @@ -25,11 +26,11 @@ public class BackButtonBehavior : BindableObject /// Bindable property for . public static readonly BindableProperty IsEnabledProperty = - BindableProperty.Create(nameof(IsEnabled), typeof(bool), typeof(BackButtonBehavior), true, BindingMode.OneWay); + BindableProperty.Create(nameof(IsEnabled), typeof(bool), typeof(BackButtonBehavior), BooleanBoxes.TrueBox, BindingMode.OneWay); /// Bindable property for . public static readonly BindableProperty IsVisibleProperty = - BindableProperty.Create(nameof(IsVisible), typeof(bool), typeof(BackButtonBehavior), true, BindingMode.OneWay); + BindableProperty.Create(nameof(IsVisible), typeof(bool), typeof(BackButtonBehavior), BooleanBoxes.TrueBox, BindingMode.OneWay); /// Bindable property for . public static readonly BindableProperty TextOverrideProperty = diff --git a/src/Controls/src/Core/Shell/BaseShellItem.cs b/src/Controls/src/Core/Shell/BaseShellItem.cs index 552fefb85869..a75414074ee3 100644 --- a/src/Controls/src/Core/Shell/BaseShellItem.cs +++ b/src/Controls/src/Core/Shell/BaseShellItem.cs @@ -49,7 +49,7 @@ public class BaseShellItem : NavigableElement, IPropertyPropagationController, I /// Bindable property for . public static readonly BindableProperty IsEnabledProperty = - BindableProperty.Create(nameof(IsEnabled), typeof(bool), typeof(BaseShellItem), true, BindingMode.OneWay); + BindableProperty.Create(nameof(IsEnabled), typeof(bool), typeof(BaseShellItem), BooleanBoxes.TrueBox, BindingMode.OneWay); /// Bindable property for . public static readonly BindableProperty TitleProperty = @@ -57,11 +57,11 @@ public class BaseShellItem : NavigableElement, IPropertyPropagationController, I /// Bindable property for . public static readonly BindableProperty IsVisibleProperty = - BindableProperty.Create(nameof(IsVisible), typeof(bool), typeof(BaseShellItem), true); + BindableProperty.Create(nameof(IsVisible), typeof(bool), typeof(BaseShellItem), BooleanBoxes.TrueBox); /// Bindable property for . public static readonly BindableProperty FlyoutItemIsVisibleProperty = - BindableProperty.Create(nameof(FlyoutItemIsVisible), typeof(bool), typeof(BaseShellItem), true, propertyChanged: OnFlyoutItemIsVisibleChanged); + BindableProperty.Create(nameof(FlyoutItemIsVisible), typeof(bool), typeof(BaseShellItem), BooleanBoxes.TrueBox, propertyChanged: OnFlyoutItemIsVisibleChanged); public BaseShellItem() { diff --git a/src/Controls/src/Core/Shell/SearchHandler.cs b/src/Controls/src/Core/Shell/SearchHandler.cs index 1bf1f5059a78..61dc0d811c2a 100644 --- a/src/Controls/src/Core/Shell/SearchHandler.cs +++ b/src/Controls/src/Core/Shell/SearchHandler.cs @@ -357,7 +357,7 @@ void ISearchHandlerController.QueryConfirmed() /// Bindable property for . public static readonly BindableProperty ClearPlaceholderEnabledProperty = - BindableProperty.Create(nameof(ClearPlaceholderEnabled), typeof(bool), typeof(SearchHandler), false); + BindableProperty.Create(nameof(ClearPlaceholderEnabled), typeof(bool), typeof(SearchHandler), BooleanBoxes.FalseBox); /// Bindable property for . public static readonly BindableProperty ClearPlaceholderHelpTextProperty = @@ -392,7 +392,7 @@ void ISearchHandlerController.QueryConfirmed() /// Bindable property for . public static readonly BindableProperty IsSearchEnabledProperty = - BindableProperty.Create(nameof(IsSearchEnabled), typeof(bool), typeof(SearchHandler), true, BindingMode.OneWay); + BindableProperty.Create(nameof(IsSearchEnabled), typeof(bool), typeof(SearchHandler), BooleanBoxes.TrueBox, BindingMode.OneWay); /// Bindable property for . public static readonly BindableProperty ItemsSourceProperty = @@ -435,7 +435,7 @@ void ISearchHandlerController.QueryConfirmed() /// Bindable property for . public static readonly BindableProperty ShowsResultsProperty = - BindableProperty.Create(nameof(ShowsResults), typeof(bool), typeof(SearchHandler), false, BindingMode.OneTime); + BindableProperty.Create(nameof(ShowsResults), typeof(bool), typeof(SearchHandler), BooleanBoxes.FalseBox, BindingMode.OneTime); private ListProxy _listProxy; diff --git a/src/Controls/src/Core/Shell/Shell.cs b/src/Controls/src/Core/Shell/Shell.cs index a082684ce11a..f0813ddcb157 100644 --- a/src/Controls/src/Core/Shell/Shell.cs +++ b/src/Controls/src/Core/Shell/Shell.cs @@ -1285,7 +1285,7 @@ public Task GoToAsync(ShellNavigationState state, bool animate, ShellNavigationQ /// The flyout can be programmatically opened and closed by setting the FlyoutIsPresented property to a boolean value that indicates whether the flyout is currently open. /// public static readonly BindableProperty FlyoutIsPresentedProperty = - BindableProperty.Create(nameof(FlyoutIsPresented), typeof(bool), typeof(Shell), false, BindingMode.TwoWay); + BindableProperty.Create(nameof(FlyoutIsPresented), typeof(bool), typeof(Shell), BooleanBoxes.FalseBox, BindingMode.TwoWay); /// Bindable property for . public static readonly BindableProperty ItemsProperty = ItemsPropertyKey.BindableProperty; diff --git a/src/Controls/src/Core/StateTrigger.cs b/src/Controls/src/Core/StateTrigger.cs index 239f2a1dfaa6..fa2700390109 100644 --- a/src/Controls/src/Core/StateTrigger.cs +++ b/src/Controls/src/Core/StateTrigger.cs @@ -1,4 +1,5 @@ #nullable disable +using Microsoft.Maui.Controls.Internals; namespace Microsoft.Maui.Controls { /// @@ -17,7 +18,7 @@ public sealed class StateTrigger : StateTriggerBase /// Bindable property for . public static readonly BindableProperty IsActiveProperty = - BindableProperty.Create(nameof(IsActive), typeof(bool), typeof(StateTrigger), default(bool), + BindableProperty.Create(nameof(IsActive), typeof(bool), typeof(StateTrigger), BooleanBoxes.FalseBox, propertyChanged: OnIsActiveChanged); static void OnIsActiveChanged(BindableObject bindable, object oldvalue, object newvalue) diff --git a/src/Controls/src/Core/SwipeView/SwipeItem.cs b/src/Controls/src/Core/SwipeView/SwipeItem.cs index 8505094c9eb6..161eec8b6cb7 100644 --- a/src/Controls/src/Core/SwipeView/SwipeItem.cs +++ b/src/Controls/src/Core/SwipeView/SwipeItem.cs @@ -1,6 +1,7 @@ #nullable disable using System; using System.ComponentModel; +using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Graphics; namespace Microsoft.Maui.Controls @@ -14,7 +15,7 @@ public partial class SwipeItem : MenuItem, Controls.ISwipeItem, Maui.ISwipeItemM public static readonly BindableProperty BackgroundColorProperty = BindableProperty.Create(nameof(BackgroundColor), typeof(Color), typeof(SwipeItem), null); /// Bindable property for . - public static readonly BindableProperty IsVisibleProperty = BindableProperty.Create(nameof(IsVisible), typeof(bool), typeof(SwipeItem), true, propertyChanged: OnIsVisibleChanged); + public static readonly BindableProperty IsVisibleProperty = BindableProperty.Create(nameof(IsVisible), typeof(bool), typeof(SwipeItem), BooleanBoxes.TrueBox, propertyChanged: OnIsVisibleChanged); /// /// Gets or sets the background color of the swipe item. This is a bindable property. diff --git a/src/Controls/src/Core/Switch/Switch.cs b/src/Controls/src/Core/Switch/Switch.cs index b988bdc84aa6..8aa4eb545076 100644 --- a/src/Controls/src/Core/Switch/Switch.cs +++ b/src/Controls/src/Core/Switch/Switch.cs @@ -2,6 +2,7 @@ using System; using System.Diagnostics; using System.Runtime.CompilerServices; +using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Graphics; namespace Microsoft.Maui.Controls @@ -29,7 +30,7 @@ public partial class Switch : View, IElementConfiguration, ISwitch public const string SwitchOffVisualState = "Off"; /// Bindable property for . This is a bindable property. - public static readonly BindableProperty IsToggledProperty = BindableProperty.Create(nameof(IsToggled), typeof(bool), typeof(Switch), false, propertyChanged: (bindable, oldValue, newValue) => + public static readonly BindableProperty IsToggledProperty = BindableProperty.Create(nameof(IsToggled), typeof(bool), typeof(Switch), BooleanBoxes.FalseBox, propertyChanged: (bindable, oldValue, newValue) => { ((Switch)bindable).Toggled?.Invoke(bindable, new ToggledEventArgs((bool)newValue)); ((Switch)bindable).ChangeVisualState(); diff --git a/src/Controls/src/Core/TabbedPage/TabbedPage.Tizen.cs b/src/Controls/src/Core/TabbedPage/TabbedPage.Tizen.cs index 11cf62260843..adda351e7440 100644 --- a/src/Controls/src/Core/TabbedPage/TabbedPage.Tizen.cs +++ b/src/Controls/src/Core/TabbedPage/TabbedPage.Tizen.cs @@ -164,7 +164,7 @@ static DataTemplate GetTemplate(TabbedPage page) class TabbedItem : Frame #pragma warning restore CS0618 // Type or member is obsolete { - static readonly BindableProperty SelectedStateProperty = BindableProperty.Create(nameof(IsSelected), typeof(bool), typeof(TabbedItem), false, propertyChanged: (b, o, n) => ((TabbedItem)b).UpdateSelectedState()); + static readonly BindableProperty SelectedStateProperty = BindableProperty.Create(nameof(IsSelected), typeof(bool), typeof(TabbedItem), BooleanBoxes.FalseBox, propertyChanged: (b, o, n) => ((TabbedItem)b).UpdateSelectedState()); static readonly BindableProperty SelectedTabColorProperty = BindableProperty.Create(nameof(SelectedTabColor), typeof(GColor), typeof(TabbedItem), default(Color), propertyChanged: (b, o, n) => ((TabbedItem)b).UpdateSelectedState()); static readonly BindableProperty UnselectedTabColorProperty = BindableProperty.Create(nameof(UnselectedTabColor), typeof(GColor), typeof(TabbedItem), default(Color), propertyChanged: (b, o, n) => ((TabbedItem)b).UpdateSelectedState()); diff --git a/src/Controls/src/Core/TableView/TableView.cs b/src/Controls/src/Core/TableView/TableView.cs index b13cf3880148..3e891fa4bc17 100644 --- a/src/Controls/src/Core/TableView/TableView.cs +++ b/src/Controls/src/Core/TableView/TableView.cs @@ -22,7 +22,7 @@ public class TableView : View, ITableViewController, IElementConfigurationBindable property for . - public static readonly BindableProperty HasUnevenRowsProperty = BindableProperty.Create(nameof(HasUnevenRows), typeof(bool), typeof(TableView), false); + public static readonly BindableProperty HasUnevenRowsProperty = BindableProperty.Create(nameof(HasUnevenRows), typeof(bool), typeof(TableView), BooleanBoxes.FalseBox); readonly Lazy> _platformConfigurationRegistry; diff --git a/src/Controls/src/Core/UriImageSource.cs b/src/Controls/src/Core/UriImageSource.cs index 4889f907d74c..5ce1935445e5 100644 --- a/src/Controls/src/Core/UriImageSource.cs +++ b/src/Controls/src/Core/UriImageSource.cs @@ -5,6 +5,7 @@ using System.Threading; using System.Threading.Tasks; using Microsoft.Extensions.Logging; +using Microsoft.Maui.Controls.Internals; namespace Microsoft.Maui.Controls { @@ -24,7 +25,7 @@ public sealed partial class UriImageSource : ImageSource, IStreamImageSource /// Bindable property for . public static readonly BindableProperty CachingEnabledProperty = BindableProperty.Create( - nameof(CachingEnabled), typeof(bool), typeof(UriImageSource), true); + nameof(CachingEnabled), typeof(bool), typeof(UriImageSource), BooleanBoxes.TrueBox); /// Gets a value indicating whether this image source is empty. public override bool IsEmpty => Uri == null; diff --git a/src/Controls/src/Core/VisualElement/VisualElement.cs b/src/Controls/src/Core/VisualElement/VisualElement.cs index f0455bb57bb5..9c84bea7165f 100644 --- a/src/Controls/src/Core/VisualElement/VisualElement.cs +++ b/src/Controls/src/Core/VisualElement/VisualElement.cs @@ -34,7 +34,7 @@ public partial class VisualElement : NavigableElement, IAnimatable, IVisualEleme /// Bindable property for . public static readonly BindableProperty InputTransparentProperty = BindableProperty.Create( - nameof(InputTransparent), typeof(bool), typeof(VisualElement), default(bool), + nameof(InputTransparent), typeof(bool), typeof(VisualElement), BooleanBoxes.FalseBox, propertyChanged: OnInputTransparentPropertyChanged, coerceValue: CoerceInputTransparentProperty); bool _isEnabledExplicit = (bool)IsEnabledProperty.DefaultValue; @@ -47,7 +47,7 @@ public partial class VisualElement : NavigableElement, IAnimatable, IVisualEleme /// Bindable property for . public static readonly BindableProperty IsEnabledProperty = BindableProperty.Create(nameof(IsEnabled), typeof(bool), - typeof(VisualElement), true, propertyChanged: OnIsEnabledPropertyChanged, coerceValue: CoerceIsEnabledProperty); + typeof(VisualElement), BooleanBoxes.TrueBox, propertyChanged: OnIsEnabledPropertyChanged, coerceValue: CoerceIsEnabledProperty); static readonly BindablePropertyKey XPropertyKey = BindableProperty.CreateReadOnly(nameof(X), typeof(double), typeof(VisualElement), default(double)); @@ -276,7 +276,7 @@ static void OnTransformChanged(BindableObject bindable, object oldValue, object propertyChanged: (b, o, n) => { (((VisualElement)b).AnchorX, ((VisualElement)b).AnchorY) = (Point)n; }); /// Bindable property for . - public static readonly BindableProperty IsVisibleProperty = BindableProperty.Create(nameof(IsVisible), typeof(bool), typeof(VisualElement), true, + public static readonly BindableProperty IsVisibleProperty = BindableProperty.Create(nameof(IsVisible), typeof(bool), typeof(VisualElement), BooleanBoxes.TrueBox, propertyChanged: (bindable, oldvalue, newvalue) => ((VisualElement)bindable).OnIsVisibleChanged((bool)oldvalue, (bool)newvalue)); /// Bindable property for . From 16f48785c47306a5f78ce4c4d315aa3bbcdd259c Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Thu, 21 May 2026 22:31:33 -0300 Subject: [PATCH 04/11] Use BooleanBoxes in SetValue/SetValueFromRenderer bool calls in Controls.Core Replace raw true/false literals with BooleanBoxes.TrueBox/FalseBox in SetValue and SetValueFromRenderer calls for bool-typed BindableProperties. Added using Microsoft.Maui.Controls.Internals to ShellPageRendererTracker.cs. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Handlers/ListView/Android/ListViewAdapter.cs | 6 +++--- .../Handlers/Shell/Android/ShellFlyoutRenderer.cs | 8 ++++---- .../Handlers/Shell/iOS/ShellPageRendererTracker.cs | 3 ++- src/Controls/src/Core/FlyoutPage/FlyoutPage.cs | 2 +- .../src/Core/Handlers/Items/Tizen/ItemTemplateAdaptor.cs | 4 ++-- src/Controls/src/Core/ListView/ListView.cs | 4 ++-- src/Controls/src/Core/RadioButton/RadioButton.cs | 2 +- src/Controls/src/Core/Shell/Shell.cs | 2 +- 8 files changed, 16 insertions(+), 15 deletions(-) diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewAdapter.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewAdapter.cs index baa49ffeb4f6..d753834f7d0f 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewAdapter.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/ListViewAdapter.cs @@ -26,7 +26,7 @@ internal class ListViewAdapter : CellAdapter static int s_dividerHorizontalDarkId = int.MinValue; #pragma warning disable CS0618 // Type or member is obsolete - internal static readonly BindableProperty IsSelectedProperty = BindableProperty.CreateAttached("IsSelected", typeof(bool), typeof(Cell), false); + internal static readonly BindableProperty IsSelectedProperty = BindableProperty.CreateAttached("IsSelected", typeof(bool), typeof(Cell), BooleanBoxes.FalseBox); #pragma warning restore CS0618 // Type or member is obsolete readonly Context _context; @@ -722,7 +722,7 @@ void Select(int index, AView view) Cell previousCell; #pragma warning restore CS0618 // Type or member is obsolete if (_selectedCell.TryGetTarget(out previousCell)) - previousCell.SetValue(IsSelectedProperty, false); + previousCell.SetValue(IsSelectedProperty, BooleanBoxes.FalseBox); } _lastSelected = view; @@ -733,7 +733,7 @@ void Select(int index, AView view) #pragma warning disable CS0618 // Type or member is obsolete Cell cell = GetCellForPosition(index); #pragma warning restore CS0618 // Type or member is obsolete - cell.SetValue(IsSelectedProperty, true); + cell.SetValue(IsSelectedProperty, BooleanBoxes.TrueBox); #pragma warning disable CS0618 // Type or member is obsolete _selectedCell = new WeakReference(cell); #pragma warning restore CS0618 // Type or member is obsolete diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFlyoutRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFlyoutRenderer.cs index c243bacdc684..d36131dceca0 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFlyoutRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFlyoutRenderer.cs @@ -83,7 +83,7 @@ void OnDrawerStateChanged(object sender, DrawerStateChangedEventArgs e) void OnDrawerOpened(object sender, DrawerOpenedEventArgs e) { - Shell.SetValueFromRenderer(Shell.FlyoutIsPresentedProperty, true); + Shell.SetValueFromRenderer(Shell.FlyoutIsPresentedProperty, BooleanBoxes.TrueBox); } void OnDrawerSlide(object sender, DrawerSlideEventArgs e) @@ -95,7 +95,7 @@ void OnDrawerSlide(object sender, DrawerSlideEventArgs e) void OnDrawerClosed(object sender, DrawerClosedEventArgs e) { - Shell.SetValueFromRenderer(Shell.FlyoutIsPresentedProperty, false); + Shell.SetValueFromRenderer(Shell.FlyoutIsPresentedProperty, BooleanBoxes.FalseBox); } #endregion IDrawerListener @@ -319,7 +319,7 @@ protected virtual void UpdateDrawerLockMode(FlyoutBehavior behavior) { case FlyoutBehavior.Disabled: CloseDrawers(); - Shell.SetValueFromRenderer(Shell.FlyoutIsPresentedProperty, false); + Shell.SetValueFromRenderer(Shell.FlyoutIsPresentedProperty, BooleanBoxes.FalseBox); _currentLockMode = LockModeLockedClosed; SetDrawerLockMode(_currentLockMode); _content.SetPadding(0, _content.PaddingTop, _content.PaddingRight, _content.PaddingBottom); @@ -332,7 +332,7 @@ protected virtual void UpdateDrawerLockMode(FlyoutBehavior behavior) break; case FlyoutBehavior.Locked: - Shell.SetValueFromRenderer(Shell.FlyoutIsPresentedProperty, true); + Shell.SetValueFromRenderer(Shell.FlyoutIsPresentedProperty, BooleanBoxes.TrueBox); _currentLockMode = LockModeLockedOpen; SetDrawerLockMode(_currentLockMode); diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs index 3d2dce60da9c..cb8a8d76a285 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs @@ -7,6 +7,7 @@ using System.Windows.Input; using CoreGraphics; using Foundation; +using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Graphics; using Microsoft.Maui.Graphics.Platform; using UIKit; @@ -704,7 +705,7 @@ void LeftBarButtonItemHandler(UIViewController controller, bool isRootPage) } else if (_flyoutBehavior == FlyoutBehavior.Flyout) { - _context?.Shell?.SetValueFromRenderer(Shell.FlyoutIsPresentedProperty, true); + _context?.Shell?.SetValueFromRenderer(Shell.FlyoutIsPresentedProperty, BooleanBoxes.TrueBox); } } diff --git a/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs b/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs index e490b7441cdc..6ab8266cc5cf 100644 --- a/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs +++ b/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs @@ -282,7 +282,7 @@ internal static void UpdateFlyoutLayoutBehavior(FlyoutPage page) { if (page is IFlyoutPageController fpc && fpc.ShouldShowSplitMode) { - page.SetValue(IsPresentedProperty, true); + page.SetValue(IsPresentedProperty, BooleanBoxes.TrueBox); if (page.FlyoutLayoutBehavior != FlyoutLayoutBehavior.Default) fpc.CanChangeIsPresented = false; } diff --git a/src/Controls/src/Core/Handlers/Items/Tizen/ItemTemplateAdaptor.cs b/src/Controls/src/Core/Handlers/Items/Tizen/ItemTemplateAdaptor.cs index e1b75635e944..9675b93cdcc2 100644 --- a/src/Controls/src/Core/Handlers/Items/Tizen/ItemTemplateAdaptor.cs +++ b/src/Controls/src/Core/Handlers/Items/Tizen/ItemTemplateAdaptor.cs @@ -77,11 +77,11 @@ public override void UpdateViewState(NView view, ViewHolderState state) { case ViewHolderState.Focused: VisualStateManager.GoToState(formsView, VisualStateManager.CommonStates.Focused); - formsView.SetValue(VisualElement.IsFocusedPropertyKey, true); + formsView.SetValue(VisualElement.IsFocusedPropertyKey, BooleanBoxes.TrueBox); break; case ViewHolderState.Normal: formsView.IsItemSelected = false; - formsView.SetValue(VisualElement.IsFocusedPropertyKey, false); + formsView.SetValue(VisualElement.IsFocusedPropertyKey, BooleanBoxes.FalseBox); break; case ViewHolderState.Selected: if (IsSelectable) diff --git a/src/Controls/src/Core/ListView/ListView.cs b/src/Controls/src/Core/ListView/ListView.cs index 922b01cf6f60..c7cbf0d488a3 100644 --- a/src/Controls/src/Core/ListView/ListView.cs +++ b/src/Controls/src/Core/ListView/ListView.cs @@ -385,7 +385,7 @@ public void BeginRefresh() if (!RefreshAllowed) return; - SetValue(IsRefreshingProperty, true, SetterSpecificity.FromHandler); + SetValue(IsRefreshingProperty, BooleanBoxes.TrueBox, SetterSpecificity.FromHandler); OnRefreshing(EventArgs.Empty); ICommand command = RefreshCommand; @@ -395,7 +395,7 @@ public void BeginRefresh() /// Exits the refreshing state by setting the property to . public void EndRefresh() { - SetValue(IsRefreshingProperty, false, SetterSpecificity.FromHandler); + SetValue(IsRefreshingProperty, BooleanBoxes.FalseBox, SetterSpecificity.FromHandler); } public event EventHandler ItemAppearing; diff --git a/src/Controls/src/Core/RadioButton/RadioButton.cs b/src/Controls/src/Core/RadioButton/RadioButton.cs index e4e3398dcdaa..df03d73e20a1 100644 --- a/src/Controls/src/Core/RadioButton/RadioButton.cs +++ b/src/Controls/src/Core/RadioButton/RadioButton.cs @@ -472,7 +472,7 @@ void SelectRadioButton(object sender, EventArgs e) { if (IsEnabled) { - SetValue(IsCheckedProperty, true, specificity: SetterSpecificity.FromHandler); + SetValue(IsCheckedProperty, BooleanBoxes.TrueBox, specificity: SetterSpecificity.FromHandler); } } diff --git a/src/Controls/src/Core/Shell/Shell.cs b/src/Controls/src/Core/Shell/Shell.cs index f0813ddcb157..b237e6be8522 100644 --- a/src/Controls/src/Core/Shell/Shell.cs +++ b/src/Controls/src/Core/Shell/Shell.cs @@ -948,7 +948,7 @@ Task OnFlyoutItemSelectedAsync(Element element, bool platformInitiated) shellContent = shellContent ?? shellSection?.CurrentItem; if (platformInitiated && FlyoutIsPresented && GetEffectiveFlyoutBehavior() != FlyoutBehavior.Locked) - SetValueFromRenderer(FlyoutIsPresentedProperty, false); + SetValueFromRenderer(FlyoutIsPresentedProperty, BooleanBoxes.FalseBox); if (shellSection == null) shellItem.PropertyChanged += OnShellItemPropertyChanged; From d8a060dd4f6e84b61152d85f9f9400c5971c269d Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Thu, 21 May 2026 22:42:41 -0300 Subject: [PATCH 05/11] Use BooleanBoxes in CreateAttached/CreateAttachedReadOnly bool properties in Controls.Core Replace raw true/false/default(bool) literals with BooleanBoxes.TrueBox/FalseBox in BindableProperty.CreateAttached and CreateAttachedReadOnly calls for bool-typed properties. Added using Microsoft.Maui.Controls.Internals to 6 files that did not already have it. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/Controls/src/Core/Interactivity/MultiCondition.cs | 3 ++- .../src/Core/Interactivity/PropertyCondition.cs | 3 ++- src/Controls/src/Core/NavigationPage/NavigationPage.cs | 4 ++-- .../AndroidSpecific/VisualElement.cs | 3 ++- .../TizenSpecific/NavigationPage.cs | 3 ++- .../Core/PlatformConfiguration/WindowsSpecific/Page.cs | 3 ++- .../WindowsSpecific/VisualElement.cs | 3 ++- .../PlatformConfiguration/iOSSpecific/VisualElement.cs | 4 ++-- src/Controls/src/Core/Shell/Shell.cs | 10 +++++----- src/Controls/src/Core/TemplatedItemsList.cs | 2 +- 10 files changed, 22 insertions(+), 16 deletions(-) diff --git a/src/Controls/src/Core/Interactivity/MultiCondition.cs b/src/Controls/src/Core/Interactivity/MultiCondition.cs index 6a32090813b3..7075526c8989 100644 --- a/src/Controls/src/Core/Interactivity/MultiCondition.cs +++ b/src/Controls/src/Core/Interactivity/MultiCondition.cs @@ -1,5 +1,6 @@ #nullable disable using System.Collections.Generic; +using Microsoft.Maui.Controls.Internals; namespace Microsoft.Maui.Controls { @@ -9,7 +10,7 @@ internal sealed class MultiCondition : Condition public MultiCondition() { - _aggregatedStateProperty = BindableProperty.CreateAttached("AggregatedState", typeof(bool), typeof(MultiCondition), false, propertyChanged: OnAggregatedStatePropertyChanged); + _aggregatedStateProperty = BindableProperty.CreateAttached("AggregatedState", typeof(bool), typeof(MultiCondition), BooleanBoxes.FalseBox, propertyChanged: OnAggregatedStatePropertyChanged); Conditions = new TriggerBase.SealedList(); } diff --git a/src/Controls/src/Core/Interactivity/PropertyCondition.cs b/src/Controls/src/Core/Interactivity/PropertyCondition.cs index ab459d04749b..d386bc788313 100644 --- a/src/Controls/src/Core/Interactivity/PropertyCondition.cs +++ b/src/Controls/src/Core/Interactivity/PropertyCondition.cs @@ -2,6 +2,7 @@ using System; using System.ComponentModel; using System.Reflection; +using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Controls.Xaml; namespace Microsoft.Maui.Controls @@ -21,7 +22,7 @@ public sealed class PropertyCondition : Condition /// public PropertyCondition() { - _stateProperty = BindableProperty.CreateAttached("State", typeof(bool), typeof(PropertyCondition), false, propertyChanged: OnStatePropertyChanged); + _stateProperty = BindableProperty.CreateAttached("State", typeof(bool), typeof(PropertyCondition), BooleanBoxes.FalseBox, propertyChanged: OnStatePropertyChanged); } /// diff --git a/src/Controls/src/Core/NavigationPage/NavigationPage.cs b/src/Controls/src/Core/NavigationPage/NavigationPage.cs index fec5d4fe5892..8b37bfd5ea90 100644 --- a/src/Controls/src/Core/NavigationPage/NavigationPage.cs +++ b/src/Controls/src/Core/NavigationPage/NavigationPage.cs @@ -19,10 +19,10 @@ public partial class NavigationPage : Page, IPageContainer, IBarElement, I /// Bindable property for attached property HasNavigationBar. public static readonly BindableProperty HasNavigationBarProperty = - BindableProperty.CreateAttached("HasNavigationBar", typeof(bool), typeof(Page), true); + BindableProperty.CreateAttached("HasNavigationBar", typeof(bool), typeof(Page), BooleanBoxes.TrueBox); /// Bindable property for attached property HasBackButton. - public static readonly BindableProperty HasBackButtonProperty = BindableProperty.CreateAttached("HasBackButton", typeof(bool), typeof(NavigationPage), true); + public static readonly BindableProperty HasBackButtonProperty = BindableProperty.CreateAttached("HasBackButton", typeof(bool), typeof(NavigationPage), BooleanBoxes.TrueBox); /// Bindable property for . public static readonly BindableProperty BarBackgroundColorProperty = BarElement.BarBackgroundColorProperty; diff --git a/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/VisualElement.cs b/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/VisualElement.cs index 14cb10ddc032..7257969178e7 100644 --- a/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/VisualElement.cs +++ b/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/VisualElement.cs @@ -1,6 +1,7 @@ #nullable disable namespace Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific { + using Microsoft.Maui.Controls.Internals; using FormsElement = Maui.Controls.VisualElement; /// @@ -64,7 +65,7 @@ public static IPlatformElementConfiguration SetElevation( /// Bindable property for attached property IsLegacyColorModeEnabled. public static readonly BindableProperty IsLegacyColorModeEnabledProperty = BindableProperty.CreateAttached("IsLegacyColorModeEnabled", typeof(bool), - typeof(FormsElement), true); + typeof(FormsElement), BooleanBoxes.TrueBox); /// /// Gets whether or not the legacy color mode for this element is enabled. diff --git a/src/Controls/src/Core/PlatformConfiguration/TizenSpecific/NavigationPage.cs b/src/Controls/src/Core/PlatformConfiguration/TizenSpecific/NavigationPage.cs index 37df0daa4d91..f5ee5803a3b9 100644 --- a/src/Controls/src/Core/PlatformConfiguration/TizenSpecific/NavigationPage.cs +++ b/src/Controls/src/Core/PlatformConfiguration/TizenSpecific/NavigationPage.cs @@ -1,6 +1,7 @@ #nullable disable namespace Microsoft.Maui.Controls.PlatformConfiguration.TizenSpecific { + using Microsoft.Maui.Controls.Internals; using FormsElement = Maui.Controls.NavigationPage; /// Provides access to the bread crumb bar for navigation pages on the Tizen platform. @@ -9,7 +10,7 @@ public static class NavigationPage #region HasBreadCrumbsBar /// Bindable property for attached property HasBreadCrumbsBar. public static readonly BindableProperty HasBreadCrumbsBarProperty - = BindableProperty.CreateAttached("HasBreadCrumbsBar", typeof(bool), typeof(FormsElement), false); + = BindableProperty.CreateAttached("HasBreadCrumbsBar", typeof(bool), typeof(FormsElement), BooleanBoxes.FalseBox); /// Returns a Boolean value that tells whether the navigation page has a bread crumb bar. /// The navigation page on the Tizen platform whose font weight icon to get. diff --git a/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/Page.cs b/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/Page.cs index dd29459aadb4..5df7d740ccce 100644 --- a/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/Page.cs +++ b/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/Page.cs @@ -4,6 +4,7 @@ using System.Linq; using System.Text; using System.Threading.Tasks; +using Microsoft.Maui.Controls.Internals; namespace Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific { @@ -75,7 +76,7 @@ public static IPlatformElementConfiguration SetToolbarPla /// public static readonly BindableProperty ToolbarDynamicOverflowEnabledProperty = BindableProperty.CreateAttached("ToolbarDynamicOverflowEnabled", typeof(bool), - typeof(FormsElement), true); + typeof(FormsElement), BooleanBoxes.TrueBox); /// /// Gets a value that indicates whether toolbar items automatically move to the overflow menu when space is limited. diff --git a/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/VisualElement.cs b/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/VisualElement.cs index 3f45972efd40..f7d9980bf8a5 100644 --- a/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/VisualElement.cs +++ b/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/VisualElement.cs @@ -1,6 +1,7 @@ #nullable disable namespace Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific { + using Microsoft.Maui.Controls.Internals; using FormsElement = Maui.Controls.VisualElement; /// Provides access to platform-specific features of visual elements on the Windows platform. @@ -156,7 +157,7 @@ public static IPlatformElementConfiguration SetAccessKeyV /// Bindable property for attached property IsLegacyColorModeEnabled. public static readonly BindableProperty IsLegacyColorModeEnabledProperty = BindableProperty.CreateAttached("IsLegacyColorModeEnabled", typeof(bool), - typeof(FormsElement), true); + typeof(FormsElement), BooleanBoxes.TrueBox); /// Gets whether legacy color mode is enabled on Windows. /// The element to query. diff --git a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/VisualElement.cs b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/VisualElement.cs index fb4b31b3277f..183fb45a62c4 100644 --- a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/VisualElement.cs +++ b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/VisualElement.cs @@ -70,7 +70,7 @@ public ShadowEffect() : base("Microsoft.Maui.Controls.ShadowEffect") { } /// Bindable property for attached property IsShadowEnabled. public static readonly BindableProperty IsShadowEnabledProperty = BindableProperty.Create("IsShadowEnabled", typeof(bool), - typeof(VisualElement), false, propertyChanged: OnIsShadowEnabledChanged); + typeof(VisualElement), BooleanBoxes.FalseBox, propertyChanged: OnIsShadowEnabledChanged); static void OnIsShadowEnabledChanged(BindableObject bindable, object oldValue, object newValue) { @@ -330,7 +330,7 @@ public static IPlatformElementConfiguration SetShadowOpacity( /// Bindable property for attached property IsLegacyColorModeEnabled. public static readonly BindableProperty IsLegacyColorModeEnabledProperty = BindableProperty.CreateAttached("IsLegacyColorModeEnabled", typeof(bool), - typeof(FormsElement), true); + typeof(FormsElement), BooleanBoxes.TrueBox); /// /// Returns whether or not the legacy color mode is enabled. diff --git a/src/Controls/src/Core/Shell/Shell.cs b/src/Controls/src/Core/Shell/Shell.cs index b237e6be8522..f3085c765832 100644 --- a/src/Controls/src/Core/Shell/Shell.cs +++ b/src/Controls/src/Core/Shell/Shell.cs @@ -68,13 +68,13 @@ static void OnBackButonBehaviorPropertyChanged(BindableObject bindable, object o /// Manages if the navigation bar is visible when a page is presented. /// public static readonly BindableProperty NavBarIsVisibleProperty = - BindableProperty.CreateAttached("NavBarIsVisible", typeof(bool), typeof(Shell), true, propertyChanged: OnNavBarIsVisibleChanged); + BindableProperty.CreateAttached("NavBarIsVisible", typeof(bool), typeof(Shell), BooleanBoxes.TrueBox, propertyChanged: OnNavBarIsVisibleChanged); /// /// Determines if the navigation bar visibility change should be animated. /// public static readonly BindableProperty NavBarVisibilityAnimationEnabledProperty = - BindableProperty.CreateAttached("NavBarVisibilityAnimationEnabled", typeof(bool), typeof(Shell), true); + BindableProperty.CreateAttached("NavBarVisibilityAnimationEnabled", typeof(bool), typeof(Shell), BooleanBoxes.TrueBox); private static void OnNavBarIsVisibleChanged(BindableObject bindable, object oldValue, object newValue) { @@ -140,7 +140,7 @@ static void ClearPropagatedNavBarIsVisible(IVisualTreeElement element, bool prop /// Controls whether the navigation bar has a shadow. /// public static readonly BindableProperty NavBarHasShadowProperty = - BindableProperty.CreateAttached("NavBarHasShadow", typeof(bool), typeof(Shell), default(bool), + BindableProperty.CreateAttached("NavBarHasShadow", typeof(bool), typeof(Shell), BooleanBoxes.FalseBox, defaultValueCreator: (b) => DeviceInfo.Platform == DevicePlatform.Android); /// @@ -163,7 +163,7 @@ static void OnSearchHandlerPropertyChanged(BindableObject bindable, object oldVa /// Flyout items are visible in the flyout by default. /// public static readonly BindableProperty FlyoutItemIsVisibleProperty = - BindableProperty.CreateAttached("FlyoutItemIsVisible", typeof(bool), typeof(Shell), true, propertyChanged: OnFlyoutItemIsVisibleChanged); + BindableProperty.CreateAttached("FlyoutItemIsVisible", typeof(bool), typeof(Shell), BooleanBoxes.TrueBox, propertyChanged: OnFlyoutItemIsVisibleChanged); public static bool GetFlyoutItemIsVisible(BindableObject obj) => (bool)obj.GetValue(FlyoutItemIsVisibleProperty); /// @@ -192,7 +192,7 @@ static void OnFlyoutItemIsVisibleChanged(BindableObject bindable, object oldValu /// The tab bar and tabs are visible in applications by default. /// public static readonly BindableProperty TabBarIsVisibleProperty = - BindableProperty.CreateAttached("TabBarIsVisible", typeof(bool), typeof(Shell), true); + BindableProperty.CreateAttached("TabBarIsVisible", typeof(bool), typeof(Shell), BooleanBoxes.TrueBox); /// /// Enables any to be displayed in the navigation bar. diff --git a/src/Controls/src/Core/TemplatedItemsList.cs b/src/Controls/src/Core/TemplatedItemsList.cs index 86f288710ebd..ee63ab85cda8 100644 --- a/src/Controls/src/Core/TemplatedItemsList.cs +++ b/src/Controls/src/Core/TemplatedItemsList.cs @@ -36,7 +36,7 @@ public sealed class TemplatedItemsList Date: Thu, 21 May 2026 23:05:11 -0300 Subject: [PATCH 06/11] Use BooleanBoxes.Box(value) in bool Set* attached property methods in Controls.Core Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/Controls/src/Core/CompressedLayout.cs | 3 ++- src/Controls/src/Core/NavigationPage/NavigationPage.cs | 4 ++-- .../AndroidSpecific/AppCompat/Application.cs | 6 +++--- .../Core/PlatformConfiguration/AndroidSpecific/Button.cs | 5 +++-- .../PlatformConfiguration/AndroidSpecific/ImageButton.cs | 3 ++- .../PlatformConfiguration/AndroidSpecific/ListView.cs | 3 ++- .../PlatformConfiguration/AndroidSpecific/TabbedPage.cs | 5 +++-- .../PlatformConfiguration/AndroidSpecific/ViewCell.cs | 3 ++- .../AndroidSpecific/VisualElement.cs | 4 ++-- .../Core/PlatformConfiguration/AndroidSpecific/WebView.cs | 7 ++++--- .../PlatformConfiguration/TizenSpecific/Application.cs | 3 ++- .../PlatformConfiguration/TizenSpecific/NavigationPage.cs | 2 +- .../PlatformConfiguration/TizenSpecific/VisualElement.cs | 3 ++- .../PlatformConfiguration/WindowsSpecific/InputView.cs | 5 +++-- .../Core/PlatformConfiguration/WindowsSpecific/Label.cs | 5 +++-- .../Core/PlatformConfiguration/WindowsSpecific/Page.cs | 4 ++-- .../PlatformConfiguration/WindowsSpecific/SearchBar.cs | 3 ++- .../PlatformConfiguration/WindowsSpecific/TabbedPage.cs | 2 +- .../WindowsSpecific/VisualElement.cs | 4 ++-- .../Core/PlatformConfiguration/WindowsSpecific/WebView.cs | 3 ++- .../Core/PlatformConfiguration/iOSSpecific/Application.cs | 7 ++++--- .../src/Core/PlatformConfiguration/iOSSpecific/Entry.cs | 3 ++- .../Core/PlatformConfiguration/iOSSpecific/FlyoutPage.cs | 3 ++- .../Core/PlatformConfiguration/iOSSpecific/ListView.cs | 2 +- .../PlatformConfiguration/iOSSpecific/NavigationPage.cs | 6 +++--- .../src/Core/PlatformConfiguration/iOSSpecific/Page.cs | 4 ++-- .../Core/PlatformConfiguration/iOSSpecific/ScrollView.cs | 2 +- .../src/Core/PlatformConfiguration/iOSSpecific/Slider.cs | 3 ++- .../PlatformConfiguration/iOSSpecific/VisualElement.cs | 8 ++++---- src/Controls/src/Core/Shell/Shell.cs | 8 ++++---- 30 files changed, 70 insertions(+), 53 deletions(-) diff --git a/src/Controls/src/Core/CompressedLayout.cs b/src/Controls/src/Core/CompressedLayout.cs index b49e33e444e3..eb6e03e82183 100644 --- a/src/Controls/src/Core/CompressedLayout.cs +++ b/src/Controls/src/Core/CompressedLayout.cs @@ -1,6 +1,7 @@ #nullable disable using System; using System.ComponentModel; +using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Graphics; namespace Microsoft.Maui.Controls @@ -27,7 +28,7 @@ public static bool GetIsHeadless(BindableObject bindable) /// The new layout compression value. to enable layout compression [Obsolete("CompressedLayout does not provide meaningful functionality and may be removed in a future release. Please remove usage of this API.")] public static void SetIsHeadless(BindableObject bindable, bool value) - => bindable.SetValue(IsHeadlessProperty, value); + => bindable.SetValue(IsHeadlessProperty, BooleanBoxes.Box(value)); static void OnIsHeadlessPropertyChanged(BindableObject bindable, object oldValue, object newValue) { diff --git a/src/Controls/src/Core/NavigationPage/NavigationPage.cs b/src/Controls/src/Core/NavigationPage/NavigationPage.cs index 8b37bfd5ea90..7bd83ea18c2a 100644 --- a/src/Controls/src/Core/NavigationPage/NavigationPage.cs +++ b/src/Controls/src/Core/NavigationPage/NavigationPage.cs @@ -362,7 +362,7 @@ public static void SetHasBackButton(Page page, bool value) { if (page == null) throw new ArgumentNullException(nameof(page)); - page.SetValue(HasBackButtonProperty, value); + page.SetValue(HasBackButtonProperty, BooleanBoxes.Box(value)); } /// Sets a value that indicates whether or not this element has a navigation bar. @@ -370,7 +370,7 @@ public static void SetHasBackButton(Page page, bool value) /// The value to set. public static void SetHasNavigationBar(BindableObject page, bool value) { - page.SetValue(HasNavigationBarProperty, value); + page.SetValue(HasNavigationBarProperty, BooleanBoxes.Box(value)); } /// The bindable parameter. diff --git a/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/AppCompat/Application.cs b/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/AppCompat/Application.cs index a56a2496a742..9d7e510351a3 100644 --- a/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/AppCompat/Application.cs +++ b/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/AppCompat/Application.cs @@ -23,7 +23,7 @@ public static bool GetSendDisappearingEventOnPause(BindableObject element) /// The new property value to assign. public static void SetSendDisappearingEventOnPause(BindableObject element, bool value) { - element.SetValue(SendDisappearingEventOnPauseProperty, value); + element.SetValue(SendDisappearingEventOnPauseProperty, BooleanBoxes.Box(value)); } /// Returns a Boolean value that controls whether the disappearing event is sent when the application is paused. @@ -59,7 +59,7 @@ public static bool GetSendAppearingEventOnResume(BindableObject element) /// The new property value to assign. public static void SetSendAppearingEventOnResume(BindableObject element, bool value) { - element.SetValue(SendAppearingEventOnResumeProperty, value); + element.SetValue(SendAppearingEventOnResumeProperty, BooleanBoxes.Box(value)); } /// Returns a Boolean value that controls whether the appearing event is sent when the application resumes. @@ -95,7 +95,7 @@ public static bool GetShouldPreserveKeyboardOnResume(BindableObject element) /// The new property value to assign. public static void SetShouldPreserveKeyboardOnResume(BindableObject element, bool value) { - element.SetValue(ShouldPreserveKeyboardOnResumeProperty, value); + element.SetValue(ShouldPreserveKeyboardOnResumeProperty, BooleanBoxes.Box(value)); } /// Returns a Boolean value that controls whether the keyboard state should be preserved when the application resumes. diff --git a/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/Button.cs b/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/Button.cs index 3270f60be551..040f8e996bb8 100644 --- a/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/Button.cs +++ b/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/Button.cs @@ -1,6 +1,7 @@ #nullable disable namespace Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific { + using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Graphics; using FormsElement = Maui.Controls.Button; @@ -24,7 +25,7 @@ public static bool GetUseDefaultPadding(BindableObject element) /// to use default padding; otherwise, . public static void SetUseDefaultPadding(BindableObject element, bool value) { - element.SetValue(UseDefaultPaddingProperty, value); + element.SetValue(UseDefaultPaddingProperty, BooleanBoxes.Box(value)); } /// Returns if the button will use the default padding. Otherwise, returns . @@ -63,7 +64,7 @@ public static bool GetUseDefaultShadow(BindableObject element) /// to use default shadow; otherwise, . public static void SetUseDefaultShadow(BindableObject element, bool value) { - element.SetValue(UseDefaultShadowProperty, value); + element.SetValue(UseDefaultShadowProperty, BooleanBoxes.Box(value)); } /// Returns if the button will use the default shadow. Otherwise, returns . diff --git a/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/ImageButton.cs b/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/ImageButton.cs index 0f7fa34b1148..3b2ca9ddfe57 100644 --- a/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/ImageButton.cs +++ b/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/ImageButton.cs @@ -1,6 +1,7 @@ #nullable disable namespace Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific { + using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Graphics; using FormsImageButton = Maui.Controls.ImageButton; @@ -24,7 +25,7 @@ public static bool GetIsShadowEnabled(BindableObject element) /// to enable shadow; otherwise, . public static void SetIsShadowEnabled(BindableObject element, bool value) { - element.SetValue(IsShadowEnabledProperty, value); + element.SetValue(IsShadowEnabledProperty, BooleanBoxes.Box(value)); } /// Gets whether the shadow effect is enabled on Android. diff --git a/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/ListView.cs b/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/ListView.cs index 6bdf9543176c..c34460882e60 100644 --- a/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/ListView.cs +++ b/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/ListView.cs @@ -2,6 +2,7 @@ namespace Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific { using System; + using Microsoft.Maui.Controls.Internals; using FormsElement = Maui.Controls.ListView; /// The list view instance that Microsoft.Maui.Controls created on the Android platform. @@ -27,7 +28,7 @@ public static bool GetIsFastScrollEnabled(BindableObject element) [Obsolete("With the deprecation of ListView, this property is obsolete. Please use CollectionView instead.")] public static void SetIsFastScrollEnabled(BindableObject element, bool value) { - element.SetValue(IsFastScrollEnabledProperty, value); + element.SetValue(IsFastScrollEnabledProperty, BooleanBoxes.Box(value)); } /// Returns a Boolean value that tells whether fast scrolling is enabled. diff --git a/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/TabbedPage.cs b/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/TabbedPage.cs index 29a541dcb331..503e3f547b8d 100644 --- a/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/TabbedPage.cs +++ b/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/TabbedPage.cs @@ -2,6 +2,7 @@ namespace Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific { using System; + using Microsoft.Maui.Controls.Internals; using FormsElement = Maui.Controls.TabbedPage; /// The tabbed page instance that Microsoft.Maui.Controls created on the Android platform. @@ -25,7 +26,7 @@ public static bool GetIsSwipePagingEnabled(BindableObject element) /// to enable swipe paging; otherwise, . public static void SetIsSwipePagingEnabled(BindableObject element, bool value) { - element.SetValue(IsSwipePagingEnabledProperty, value); + element.SetValue(IsSwipePagingEnabledProperty, BooleanBoxes.Box(value)); } /// Gets a Boolean value that controls whether swipe paging is enabled. @@ -81,7 +82,7 @@ public static bool GetIsSmoothScrollEnabled(BindableObject element) /// to enable smooth scroll; otherwise, . public static void SetIsSmoothScrollEnabled(BindableObject element, bool value) { - element.SetValue(IsSmoothScrollEnabledProperty, value); + element.SetValue(IsSmoothScrollEnabledProperty, BooleanBoxes.Box(value)); } /// Gets whether smooth scrolling is enabled for this. diff --git a/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/ViewCell.cs b/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/ViewCell.cs index 3c2b3911f43d..e3e6f97e44dd 100644 --- a/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/ViewCell.cs +++ b/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/ViewCell.cs @@ -2,6 +2,7 @@ namespace Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific { using System; + using Microsoft.Maui.Controls.Internals; using FormsCell = Maui.Controls.Cell; /// Android-specific context actions behavior for ViewCell in ListView. @@ -37,7 +38,7 @@ public static bool GetIsContextActionsLegacyModeEnabled(BindableObject element) [Obsolete("With the deprecation of ListView, this class is obsolete. Please use CollectionView instead.")] public static void SetIsContextActionsLegacyModeEnabled(BindableObject element, bool value) { - element.SetValue(IsContextActionsLegacyModeEnabledProperty, value); + element.SetValue(IsContextActionsLegacyModeEnabledProperty, BooleanBoxes.Box(value)); } /// Gets whether the legacy context actions mode is enabled on Android. diff --git a/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/VisualElement.cs b/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/VisualElement.cs index 7257969178e7..884d49e19808 100644 --- a/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/VisualElement.cs +++ b/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/VisualElement.cs @@ -84,7 +84,7 @@ public static bool GetIsLegacyColorModeEnabled(BindableObject element) /// to enable legacy color mode. Otherwise, . public static void SetIsLegacyColorModeEnabled(BindableObject element, bool value) { - element.SetValue(IsLegacyColorModeEnabledProperty, value); + element.SetValue(IsLegacyColorModeEnabledProperty, BooleanBoxes.Box(value)); } /// @@ -106,7 +106,7 @@ public static bool GetIsLegacyColorModeEnabled(this IPlatformElementConfiguratio public static IPlatformElementConfiguration SetIsLegacyColorModeEnabled( this IPlatformElementConfiguration config, bool value) { - config.Element.SetValue(IsLegacyColorModeEnabledProperty, value); + config.Element.SetValue(IsLegacyColorModeEnabledProperty, BooleanBoxes.Box(value)); return config; } diff --git a/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/WebView.cs b/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/WebView.cs index 9177872b5e8f..f7a11b7e1b98 100644 --- a/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/WebView.cs +++ b/src/Controls/src/Core/PlatformConfiguration/AndroidSpecific/WebView.cs @@ -2,6 +2,7 @@ namespace Microsoft.Maui.Controls.PlatformConfiguration.AndroidSpecific { + using Microsoft.Maui.Controls.Internals; using FormsElement = Maui.Controls.WebView; /// Enumerates web view behaviors when handling mixed content. @@ -67,7 +68,7 @@ public static bool GetEnableZoomControls(FormsElement element) /// to enable zoom controls; otherwise, . public static void SetEnableZoomControls(FormsElement element, bool value) { - element.SetValue(EnableZoomControlsProperty, value); + element.SetValue(EnableZoomControlsProperty, BooleanBoxes.Box(value)); } /// The platform configuration for the element on which to perform the operation. @@ -106,7 +107,7 @@ public static bool GetDisplayZoomControls(FormsElement element) /// to display zoom controls; otherwise, . public static void SetDisplayZoomControls(FormsElement element, bool value) { - element.SetValue(DisplayZoomControlsProperty, value); + element.SetValue(DisplayZoomControlsProperty, BooleanBoxes.Box(value)); } /// The platform configuration for the element on which to perform the operation. @@ -154,7 +155,7 @@ public static bool GetJavaScriptEnabled(FormsElement element) /// The boolean value indicating whether JavaScript should be enabled. public static void SetJavaScriptEnabled(FormsElement element, bool value) { - element.SetValue(JavaScriptEnabledProperty, value); + element.SetValue(JavaScriptEnabledProperty, BooleanBoxes.Box(value)); } /// diff --git a/src/Controls/src/Core/PlatformConfiguration/TizenSpecific/Application.cs b/src/Controls/src/Core/PlatformConfiguration/TizenSpecific/Application.cs index 073fafe78fa0..036e1bec94a0 100644 --- a/src/Controls/src/Core/PlatformConfiguration/TizenSpecific/Application.cs +++ b/src/Controls/src/Core/PlatformConfiguration/TizenSpecific/Application.cs @@ -3,6 +3,7 @@ namespace Microsoft.Maui.Controls.PlatformConfiguration.TizenSpecific { + using Microsoft.Maui.Controls.Internals; using FormsElement = Maui.Controls.Application; /// Provides Tizen-specific platform configuration for application-level features. @@ -24,7 +25,7 @@ public static bool GetUseBezelInteraction(BindableObject element) /// to enable bezel interaction; otherwise, . public static void SetUseBezelInteraction(BindableObject element, bool value) { - element.SetValue(UseBezelInteractionProperty, value); + element.SetValue(UseBezelInteractionProperty, BooleanBoxes.Box(value)); } /// Gets the value that indicates whether bezel interaction is enabled. diff --git a/src/Controls/src/Core/PlatformConfiguration/TizenSpecific/NavigationPage.cs b/src/Controls/src/Core/PlatformConfiguration/TizenSpecific/NavigationPage.cs index f5ee5803a3b9..b957c07a1dad 100644 --- a/src/Controls/src/Core/PlatformConfiguration/TizenSpecific/NavigationPage.cs +++ b/src/Controls/src/Core/PlatformConfiguration/TizenSpecific/NavigationPage.cs @@ -25,7 +25,7 @@ public static bool GetHasBreadCrumbsBar(BindableObject element) /// to show a bread crumb bar; otherwise, . public static void SetHasBreadCrumbsBar(BindableObject element, bool value) { - element.SetValue(HasBreadCrumbsBarProperty, value); + element.SetValue(HasBreadCrumbsBarProperty, BooleanBoxes.Box(value)); } /// Returns a Boolean value that tells whether the navigation page has a bread crumb bar. diff --git a/src/Controls/src/Core/PlatformConfiguration/TizenSpecific/VisualElement.cs b/src/Controls/src/Core/PlatformConfiguration/TizenSpecific/VisualElement.cs index 5a29365a2667..f216701ff361 100644 --- a/src/Controls/src/Core/PlatformConfiguration/TizenSpecific/VisualElement.cs +++ b/src/Controls/src/Core/PlatformConfiguration/TizenSpecific/VisualElement.cs @@ -6,6 +6,7 @@ namespace Microsoft.Maui.Controls.PlatformConfiguration.TizenSpecific { using static Microsoft.Maui.ApplicationModel.Permissions; + using Microsoft.Maui.Controls.Internals; using FormsElement = Maui.Controls.VisualElement; /// @@ -103,7 +104,7 @@ public static IPlatformElementConfiguration SetStyle(this I /// The new focus participation value. public static void SetFocusAllowed(BindableObject element, bool value) { - element.SetValue(IsFocusAllowedProperty, value); + element.SetValue(IsFocusAllowedProperty, BooleanBoxes.Box(value)); } /// diff --git a/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/InputView.cs b/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/InputView.cs index e87df2baff6d..12f5184d92f3 100644 --- a/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/InputView.cs +++ b/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/InputView.cs @@ -3,6 +3,7 @@ namespace Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific { + using Microsoft.Maui.Controls.Internals; using FormsElement = Maui.Controls.InputView; /// Provides access to reading order detection on the Windows platform. @@ -16,7 +17,7 @@ public static class InputView /// to detect reading order from content. public static void SetDetectReadingOrderFromContent(BindableObject element, bool value) { - element.SetValue(DetectReadingOrderFromContentProperty, value); + element.SetValue(DetectReadingOrderFromContentProperty, BooleanBoxes.Box(value)); } /// Gets whether reading order (LTR/RTL) is detected from content on Windows. @@ -42,7 +43,7 @@ public static bool GetDetectReadingOrderFromContent(BindableObject element) public static IPlatformElementConfiguration SetDetectReadingOrderFromContent( this IPlatformElementConfiguration config, bool value) { - config.Element.SetValue(DetectReadingOrderFromContentProperty, value); + config.Element.SetValue(DetectReadingOrderFromContentProperty, BooleanBoxes.Box(value)); return config; } } diff --git a/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/Label.cs b/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/Label.cs index 5ef9a8b8bf19..1ec22ea1edbc 100644 --- a/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/Label.cs +++ b/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/Label.cs @@ -3,6 +3,7 @@ namespace Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific { + using Microsoft.Maui.Controls.Internals; using FormsElement = Maui.Controls.Label; /// Provides access to reading order detection on the Windows platform. @@ -16,7 +17,7 @@ public static class Label /// to detect reading order from content. public static void SetDetectReadingOrderFromContent(BindableObject element, bool value) { - element.SetValue(DetectReadingOrderFromContentProperty, value); + element.SetValue(DetectReadingOrderFromContentProperty, BooleanBoxes.Box(value)); } /// Gets whether reading order (LTR/RTL) is detected from label content on Windows. @@ -42,7 +43,7 @@ public static bool GetDetectReadingOrderFromContent(BindableObject element) public static IPlatformElementConfiguration SetDetectReadingOrderFromContent( this IPlatformElementConfiguration config, bool value) { - config.Element.SetValue(DetectReadingOrderFromContentProperty, value); + config.Element.SetValue(DetectReadingOrderFromContentProperty, BooleanBoxes.Box(value)); return config; } } diff --git a/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/Page.cs b/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/Page.cs index 5df7d740ccce..860c7ccc70f6 100644 --- a/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/Page.cs +++ b/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/Page.cs @@ -95,7 +95,7 @@ public static bool GetToolbarDynamicOverflowEnabled(BindableObject element) /// A value that indicates whether toolbar items automatically move to the overflow menu when space is limited public static void SetToolbarDynamicOverflowEnabled(BindableObject element, bool value) { - element.SetValue(ToolbarDynamicOverflowEnabledProperty, value); + element.SetValue(ToolbarDynamicOverflowEnabledProperty, BooleanBoxes.Box(value)); } /// @@ -117,7 +117,7 @@ public static bool GetToolbarDynamicOverflowEnabled(this IPlatformElementConfigu public static IPlatformElementConfiguration SetToolbarDynamicOverflowEnabled( this IPlatformElementConfiguration config, bool value) { - config.Element.SetValue(ToolbarDynamicOverflowEnabledProperty, value); + config.Element.SetValue(ToolbarDynamicOverflowEnabledProperty, BooleanBoxes.Box(value)); return config; } diff --git a/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/SearchBar.cs b/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/SearchBar.cs index 5bf84048da84..02ded3e0cd01 100644 --- a/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/SearchBar.cs +++ b/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/SearchBar.cs @@ -5,6 +5,7 @@ namespace Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific { + using Microsoft.Maui.Controls.Internals; using FormsElement = Maui.Controls.SearchBar; /// Provides control over the spellchecker on search bars. @@ -19,7 +20,7 @@ public static class SearchBar /// to enable spell checking. public static void SetIsSpellCheckEnabled(BindableObject element, bool value) { - element.SetValue(IsSpellCheckEnabledProperty, value); + element.SetValue(IsSpellCheckEnabledProperty, BooleanBoxes.Box(value)); } /// Gets whether spell checking is enabled for the search bar on Windows. diff --git a/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/TabbedPage.cs b/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/TabbedPage.cs index 6e210e85c4a5..6fd03b9f3a2e 100644 --- a/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/TabbedPage.cs +++ b/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/TabbedPage.cs @@ -25,7 +25,7 @@ public static class TabbedPage /// to enable header icons. public static void SetHeaderIconsEnabled(BindableObject element, bool value) { - element.SetValue(HeaderIconsEnabledProperty, value); + element.SetValue(HeaderIconsEnabledProperty, BooleanBoxes.Box(value)); } /// Gets whether tab header icons are displayed on Windows. diff --git a/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/VisualElement.cs b/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/VisualElement.cs index f7d9980bf8a5..fd4cfc316e02 100644 --- a/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/VisualElement.cs +++ b/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/VisualElement.cs @@ -172,7 +172,7 @@ public static bool GetIsLegacyColorModeEnabled(BindableObject element) /// to enable legacy color mode. public static void SetIsLegacyColorModeEnabled(BindableObject element, bool value) { - element.SetValue(IsLegacyColorModeEnabledProperty, value); + element.SetValue(IsLegacyColorModeEnabledProperty, BooleanBoxes.Box(value)); } /// Gets whether legacy color mode is enabled on Windows. @@ -190,7 +190,7 @@ public static bool GetIsLegacyColorModeEnabled(this IPlatformElementConfiguratio public static IPlatformElementConfiguration SetIsLegacyColorModeEnabled( this IPlatformElementConfiguration config, bool value) { - config.Element.SetValue(IsLegacyColorModeEnabledProperty, value); + config.Element.SetValue(IsLegacyColorModeEnabledProperty, BooleanBoxes.Box(value)); return config; } diff --git a/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/WebView.cs b/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/WebView.cs index 68cfc0bb5791..530311558422 100644 --- a/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/WebView.cs +++ b/src/Controls/src/Core/PlatformConfiguration/WindowsSpecific/WebView.cs @@ -2,6 +2,7 @@ namespace Microsoft.Maui.Controls.PlatformConfiguration.WindowsSpecific { + using Microsoft.Maui.Controls.Internals; using FormsElement = Maui.Controls.WebView; /// Controls whether JavaScript alerts are enabled for a web view. @@ -23,7 +24,7 @@ public static bool GetIsJavaScriptAlertEnabled(BindableObject element) /// to enable JavaScript alerts. public static void SetIsJavaScriptAlertEnabled(BindableObject element, bool value) { - element.SetValue(IsJavaScriptAlertEnabledProperty, value); + element.SetValue(IsJavaScriptAlertEnabledProperty, BooleanBoxes.Box(value)); } /// Returns a Boolean value that tells whether the web view allows JavaScript alerts. diff --git a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Application.cs b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Application.cs index f850fb20700a..8d80b8c3f32d 100644 --- a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Application.cs +++ b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Application.cs @@ -1,6 +1,7 @@ #nullable disable namespace Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific { + using Microsoft.Maui.Controls.Internals; using FormsElement = Maui.Controls.Application; /// Provides control over simultaneous recognition for pan gesture recognizers. @@ -23,7 +24,7 @@ public static bool GetPanGestureRecognizerShouldRecognizeSimultaneously(Bindable /// to enable simultaneous recognition; otherwise, . public static void SetPanGestureRecognizerShouldRecognizeSimultaneously(BindableObject element, bool value) { - element.SetValue(PanGestureRecognizerShouldRecognizeSimultaneouslyProperty, value); + element.SetValue(PanGestureRecognizerShouldRecognizeSimultaneouslyProperty, BooleanBoxes.Box(value)); } /// Gets whether pan gesture recognizers can recognize gestures simultaneously with other gesture recognizers. @@ -62,7 +63,7 @@ public static bool GetHandleControlUpdatesOnMainThread(BindableObject element) /// to handle updates on the main thread; otherwise, . public static void SetHandleControlUpdatesOnMainThread(BindableObject element, bool value) { - element.SetValue(HandleControlUpdatesOnMainThreadProperty, value); + element.SetValue(HandleControlUpdatesOnMainThreadProperty, BooleanBoxes.Box(value)); } /// Gets whether control property updates are processed on the main thread on iOS. @@ -101,7 +102,7 @@ public static bool GetEnableAccessibilityScalingForNamedFontSizes(BindableObject /// to enable accessibility scaling; otherwise, . public static void SetEnableAccessibilityScalingForNamedFontSizes(BindableObject element, bool value) { - element.SetValue(EnableAccessibilityScalingForNamedFontSizesProperty, value); + element.SetValue(EnableAccessibilityScalingForNamedFontSizesProperty, BooleanBoxes.Box(value)); } /// Gets whether named font sizes respond to iOS Dynamic Type accessibility settings. diff --git a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Entry.cs b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Entry.cs index ffb62d9e3abd..f33653180115 100644 --- a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Entry.cs +++ b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Entry.cs @@ -1,5 +1,6 @@ #nullable disable using System; +using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Graphics; namespace Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific @@ -30,7 +31,7 @@ public static bool GetAdjustsFontSizeToFitWidth(BindableObject element) /// to enable auto font size adjustment; otherwise, . public static void SetAdjustsFontSizeToFitWidth(BindableObject element, bool value) { - element.SetValue(AdjustsFontSizeToFitWidthProperty, value); + element.SetValue(AdjustsFontSizeToFitWidthProperty, BooleanBoxes.Box(value)); } /// Returns a Boolean value that tells whether the entry control automatically adjusts the font size. diff --git a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/FlyoutPage.cs b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/FlyoutPage.cs index 33b77644ab3f..a2a34abf60cb 100644 --- a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/FlyoutPage.cs +++ b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/FlyoutPage.cs @@ -2,6 +2,7 @@ namespace Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific { + using Microsoft.Maui.Controls.Internals; using FormsElement = Maui.Controls.FlyoutPage; /// Provides iOS-specific configuration for FlyoutPage shadow effects. @@ -24,7 +25,7 @@ public static bool GetApplyShadow(BindableObject element) /// to apply shadow; otherwise, . public static void SetApplyShadow(BindableObject element, bool value) { - element.SetValue(ApplyShadowProperty, value); + element.SetValue(ApplyShadowProperty, BooleanBoxes.Box(value)); } /// Sets whether a drop shadow is applied to the detail page when the flyout is revealed on iOS. diff --git a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/ListView.cs b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/ListView.cs index 91cca1b1a61f..31ed43d83c2c 100644 --- a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/ListView.cs +++ b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/ListView.cs @@ -125,7 +125,7 @@ public static bool GetRowAnimationsEnabled(BindableObject element) [Obsolete("With the deprecation of ListView, this property is obsolete. Please use CollectionView instead.")] public static void SetRowAnimationsEnabled(BindableObject element, bool value) { - element.SetValue(RowAnimationsEnabledProperty, value); + element.SetValue(RowAnimationsEnabledProperty, BooleanBoxes.Box(value)); } /// Sets whether row animations are enabled for the ListView on iOS. diff --git a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/NavigationPage.cs b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/NavigationPage.cs index c4f585afa574..97d694bac876 100644 --- a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/NavigationPage.cs +++ b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/NavigationPage.cs @@ -32,7 +32,7 @@ public static bool GetIsNavigationBarTranslucent(BindableObject element) [Obsolete("IsNavigationBarTranslucent is deprecated. The Translucent will be enabled by default by setting the BarBackgroundColor to a transparent color.")] public static void SetIsNavigationBarTranslucent(BindableObject element, bool value) { - element.SetValue(IsNavigationBarTranslucentProperty, value); + element.SetValue(IsNavigationBarTranslucentProperty, BooleanBoxes.Box(value)); } /// Returns a Boolean value that tells whether the navigation bar on the platform-specific navigation page is translucent. @@ -135,7 +135,7 @@ public static bool GetPrefersLargeTitles(BindableObject element) /// to prefer large titles; otherwise, . public static void SetPrefersLargeTitles(BindableObject element, bool value) { - element.SetValue(PrefersLargeTitlesProperty, value); + element.SetValue(PrefersLargeTitlesProperty, BooleanBoxes.Box(value)); } /// Sets whether iOS 11+ large titles are displayed in the navigation bar. @@ -174,7 +174,7 @@ public static bool GetHideNavigationBarSeparator(BindableObject element) /// to hide the separator; otherwise, . public static void SetHideNavigationBarSeparator(BindableObject element, bool value) { - element.SetValue(HideNavigationBarSeparatorProperty, value); + element.SetValue(HideNavigationBarSeparatorProperty, BooleanBoxes.Box(value)); } /// Sets whether to hide the navigation bar separator line on iOS. diff --git a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Page.cs b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Page.cs index 14b55136a102..1fff2d6de9fd 100644 --- a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Page.cs +++ b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Page.cs @@ -150,7 +150,7 @@ public static bool GetUseSafeArea(BindableObject element) [System.Obsolete("Use SafeAreaEdges attached property instead for per-edge safe area control.")] public static void SetUseSafeArea(BindableObject element, bool value) { - element.SetValue(UseSafeAreaProperty, value); + element.SetValue(UseSafeAreaProperty, BooleanBoxes.Box(value)); } /// @@ -438,7 +438,7 @@ public static bool GetPrefersHomeIndicatorAutoHidden(BindableObject element) /// if hide the home indicator; otherwise, . public static void SetPrefersHomeIndicatorAutoHidden(BindableObject element, bool value) { - element.SetValue(PrefersHomeIndicatorAutoHiddenProperty, value); + element.SetValue(PrefersHomeIndicatorAutoHiddenProperty, BooleanBoxes.Box(value)); } /// diff --git a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/ScrollView.cs b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/ScrollView.cs index 5966b8c12dc5..1810f2acaa91 100644 --- a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/ScrollView.cs +++ b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/ScrollView.cs @@ -23,7 +23,7 @@ public static bool GetShouldDelayContentTouches(BindableObject element) /// to delay; for immediate touch response. public static void SetShouldDelayContentTouches(BindableObject element, bool value) { - element.SetValue(ShouldDelayContentTouchesProperty, value); + element.SetValue(ShouldDelayContentTouchesProperty, BooleanBoxes.Box(value)); } /// Returns a Boolean value that tells whether iOS will wait to determine if a touch is intended as a scroll, or scroll immediately. diff --git a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Slider.cs b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Slider.cs index b4701425ba2f..8fd5cd689f5b 100644 --- a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Slider.cs +++ b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/Slider.cs @@ -1,6 +1,7 @@ #nullable disable namespace Microsoft.Maui.Controls.PlatformConfiguration.iOSSpecific { + using Microsoft.Maui.Controls.Internals; using FormsElement = Maui.Controls.Slider; /// Platform-specific functionality for sliders the iOS platform. @@ -22,7 +23,7 @@ public static bool GetUpdateOnTap(BindableObject element) /// to update on tap; otherwise, . public static void SetUpdateOnTap(BindableObject element, bool value) { - element.SetValue(UpdateOnTapProperty, value); + element.SetValue(UpdateOnTapProperty, BooleanBoxes.Box(value)); } /// Gets whether the slider value updates when the user taps on the track on iOS. diff --git a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/VisualElement.cs b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/VisualElement.cs index 183fb45a62c4..01fb61ca04ca 100644 --- a/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/VisualElement.cs +++ b/src/Controls/src/Core/PlatformConfiguration/iOSSpecific/VisualElement.cs @@ -110,7 +110,7 @@ public static bool GetIsShadowEnabled(BindableObject element) /// to enable the shadow. Otherwise, . public static void SetIsShadowEnabled(BindableObject element, bool value) { - element.SetValue(IsShadowEnabledProperty, value); + element.SetValue(IsShadowEnabledProperty, BooleanBoxes.Box(value)); } /// @@ -349,7 +349,7 @@ public static bool GetIsLegacyColorModeEnabled(BindableObject element) /// to enable legacy color mode. Otherwise, . public static void SetIsLegacyColorModeEnabled(BindableObject element, bool value) { - element.SetValue(IsLegacyColorModeEnabledProperty, value); + element.SetValue(IsLegacyColorModeEnabledProperty, BooleanBoxes.Box(value)); } /// @@ -371,7 +371,7 @@ public static bool GetIsLegacyColorModeEnabled(this IPlatformElementConfiguratio public static IPlatformElementConfiguration SetIsLegacyColorModeEnabled( this IPlatformElementConfiguration config, bool value) { - config.Element.SetValue(IsLegacyColorModeEnabledProperty, value); + config.Element.SetValue(IsLegacyColorModeEnabledProperty, BooleanBoxes.Box(value)); return config; } @@ -397,7 +397,7 @@ public static bool GetCanBecomeFirstResponder(BindableObject element) /// to set this element as the first responder. Otherwise, . public static void SetCanBecomeFirstResponder(BindableObject element, bool value) { - element.SetValue(CanBecomeFirstResponderProperty, value); + element.SetValue(CanBecomeFirstResponderProperty, BooleanBoxes.Box(value)); } /// diff --git a/src/Controls/src/Core/Shell/Shell.cs b/src/Controls/src/Core/Shell/Shell.cs index f3085c765832..849f6a890fff 100644 --- a/src/Controls/src/Core/Shell/Shell.cs +++ b/src/Controls/src/Core/Shell/Shell.cs @@ -367,7 +367,7 @@ internal static BackButtonBehavior GetEffectiveBackButtonBehavior(BindableObject /// /// The object that modifies the navigation bar visibility. /// to set the navigation bar as visible; otherwise, . - public static void SetNavBarIsVisible(BindableObject obj, bool value) => obj.SetValue(NavBarIsVisibleProperty, value); + public static void SetNavBarIsVisible(BindableObject obj, bool value) => obj.SetValue(NavBarIsVisibleProperty, BooleanBoxes.Box(value)); /// /// Gets a value indicating whether the navigation bar visibility change is animated for the given . @@ -382,7 +382,7 @@ internal static BackButtonBehavior GetEffectiveBackButtonBehavior(BindableObject /// /// The object that modifies the animation setting. /// to enable animation; otherwise, . - public static void SetNavBarVisibilityAnimationEnabled(BindableObject obj, bool value) => obj.SetValue(NavBarVisibilityAnimationEnabledProperty, value); + public static void SetNavBarVisibilityAnimationEnabled(BindableObject obj, bool value) => obj.SetValue(NavBarVisibilityAnimationEnabledProperty, BooleanBoxes.Box(value)); /// @@ -398,7 +398,7 @@ internal static BackButtonBehavior GetEffectiveBackButtonBehavior(BindableObject /// /// The object that modifies if the navigation bar has a shadow. /// Manages if the navigation bar has a shadow. - public static void SetNavBarHasShadow(BindableObject obj, bool value) => obj.SetValue(NavBarHasShadowProperty, value); + public static void SetNavBarHasShadow(BindableObject obj, bool value) => obj.SetValue(NavBarHasShadowProperty, BooleanBoxes.Box(value)); /// /// Gets the integrated search functionality. @@ -431,7 +431,7 @@ internal static BackButtonBehavior GetEffectiveBackButtonBehavior(BindableObject /// /// The object that modifies the tabs visibility. /// to set the tab bar as visible; otherwise, . - public static void SetTabBarIsVisible(BindableObject obj, bool value) => obj.SetValue(TabBarIsVisibleProperty, value); + public static void SetTabBarIsVisible(BindableObject obj, bool value) => obj.SetValue(TabBarIsVisibleProperty, BooleanBoxes.Box(value)); /// /// Gets any to be displayed in the navigation bar when the given is active. From 39aa77af6874d86926700922fdde04e084087ec8 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Sat, 23 May 2026 15:22:05 -0300 Subject: [PATCH 07/11] add unit tests --- .../tests/Core.UnitTests/BooleanBoxesTests.cs | 72 +++++++++++++++++++ 1 file changed, 72 insertions(+) create mode 100644 src/Controls/tests/Core.UnitTests/BooleanBoxesTests.cs diff --git a/src/Controls/tests/Core.UnitTests/BooleanBoxesTests.cs b/src/Controls/tests/Core.UnitTests/BooleanBoxesTests.cs new file mode 100644 index 000000000000..7cd81e786f63 --- /dev/null +++ b/src/Controls/tests/Core.UnitTests/BooleanBoxesTests.cs @@ -0,0 +1,72 @@ +using Microsoft.Maui.Controls.Internals; +using Xunit; + +namespace Microsoft.Maui.Controls.Core.UnitTests; + +public class BooleanBoxesTests : BaseTestFixture +{ + [Fact] + public void TrueBoxIsBoxedTrue() + { + Assert.Equal(true, BooleanBoxes.TrueBox); + Assert.IsType(BooleanBoxes.TrueBox); + } + + [Fact] + public void FalseBoxIsBoxedFalse() + { + Assert.Equal(false, BooleanBoxes.FalseBox); + Assert.IsType(BooleanBoxes.FalseBox); + } + + [Fact] + public void TrueBoxAndFalseBoxAreDifferentInstances() + { + Assert.NotSame(BooleanBoxes.TrueBox, BooleanBoxes.FalseBox); + } + + [Fact] + public void BoxTrueReturnsTrueBox() + { + var result = BooleanBoxes.Box(true); + Assert.Same(BooleanBoxes.TrueBox, result); + } + + [Fact] + public void BoxFalseReturnsFalseBox() + { + var result = BooleanBoxes.Box(false); + Assert.Same(BooleanBoxes.FalseBox, result); + } + + [Fact] + public void BoxNullableTrueReturnsTrueBox() + { + bool? value = true; + var result = BooleanBoxes.Box(value); + Assert.Same(BooleanBoxes.TrueBox, result); + } + + [Fact] + public void BoxNullableFalseReturnsFalseBox() + { + bool? value = false; + var result = BooleanBoxes.Box(value); + Assert.Same(BooleanBoxes.FalseBox, result); + } + + [Fact] + public void BoxNullableNullReturnsNull() + { + bool? value = null; + var result = BooleanBoxes.Box(value); + Assert.Null(result); + } + + [Fact] + public void BoxReturnsSameReferenceOnRepeatedCalls() + { + Assert.Same(BooleanBoxes.Box(true), BooleanBoxes.Box(true)); + Assert.Same(BooleanBoxes.Box(false), BooleanBoxes.Box(false)); + } +} \ No newline at end of file From 72a704f792b6f958e0bfd1261db1667800c023d6 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Sun, 24 May 2026 18:14:16 -0300 Subject: [PATCH 08/11] Remove global using for Internals; add explicit using to ActivityIndicator The global using Microsoft.Maui.Controls.Internals caused CS0104 ambiguous reference errors for PreserveAttribute in iOS files that also import Foundation. Remove the global using and add an explicit using to the one file that was missing it (ActivityIndicator.cs). Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/Controls/src/Core/ActivityIndicator/ActivityIndicator.cs | 1 + src/Controls/src/Core/GlobalNamespaces.cs | 1 - 2 files changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controls/src/Core/ActivityIndicator/ActivityIndicator.cs b/src/Controls/src/Core/ActivityIndicator/ActivityIndicator.cs index 8d2663c77b55..7fb95a20c5a4 100644 --- a/src/Controls/src/Core/ActivityIndicator/ActivityIndicator.cs +++ b/src/Controls/src/Core/ActivityIndicator/ActivityIndicator.cs @@ -2,6 +2,7 @@ using System; using System.Diagnostics; +using Microsoft.Maui.Controls.Internals; using Microsoft.Maui.Graphics; namespace Microsoft.Maui.Controls diff --git a/src/Controls/src/Core/GlobalNamespaces.cs b/src/Controls/src/Core/GlobalNamespaces.cs index b3e66d084da1..40c8a90ceba8 100644 --- a/src/Controls/src/Core/GlobalNamespaces.cs +++ b/src/Controls/src/Core/GlobalNamespaces.cs @@ -1,4 +1,3 @@ global using Microsoft.Maui; global using Microsoft.Maui.Handlers; global using Microsoft.Maui.Platform; -global using Microsoft.Maui.Controls.Internals; From 0a44fa91a6cd15cb030b883d8d100def4b92d9f5 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Mon, 8 Jun 2026 20:12:56 -0300 Subject: [PATCH 09/11] code review --- .../Handlers/Shell/Android/ShellFlyoutRenderer.cs | 2 +- src/Controls/src/Core/Internals/BooleanBoxes.cs | 2 +- src/Controls/src/Core/RefreshView/RefreshView.cs | 4 ++-- src/Controls/src/Core/Shell/Shell.cs | 8 ++++---- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFlyoutRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFlyoutRenderer.cs index d36131dceca0..106f5c7a9aa7 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFlyoutRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellFlyoutRenderer.cs @@ -332,7 +332,7 @@ protected virtual void UpdateDrawerLockMode(FlyoutBehavior behavior) break; case FlyoutBehavior.Locked: - Shell.SetValueFromRenderer(Shell.FlyoutIsPresentedProperty, BooleanBoxes.TrueBox); + Shell.SetValueFromRenderer(Shell.FlyoutIsPresentedProperty, BooleanBoxes.TrueBox); _currentLockMode = LockModeLockedOpen; SetDrawerLockMode(_currentLockMode); diff --git a/src/Controls/src/Core/Internals/BooleanBoxes.cs b/src/Controls/src/Core/Internals/BooleanBoxes.cs index 7a553e0f7572..8c69be39721d 100644 --- a/src/Controls/src/Core/Internals/BooleanBoxes.cs +++ b/src/Controls/src/Core/Internals/BooleanBoxes.cs @@ -18,4 +18,4 @@ internal static object Box(bool value) => false => FalseBox, null => null, }; -} \ No newline at end of file +} diff --git a/src/Controls/src/Core/RefreshView/RefreshView.cs b/src/Controls/src/Core/RefreshView/RefreshView.cs index 3f2a1bab43fa..62eaf19a7962 100644 --- a/src/Controls/src/Core/RefreshView/RefreshView.cs +++ b/src/Controls/src/Core/RefreshView/RefreshView.cs @@ -123,7 +123,7 @@ public Color RefreshColor /// Bindable property for . public static readonly BindableProperty IsRefreshEnabledProperty = - BindableProperty.Create(nameof(IsRefreshEnabled), typeof(bool), typeof(RefreshView), BooleanBoxes.TrueBox, + BindableProperty.Create(nameof(IsRefreshEnabled), typeof(bool), typeof(RefreshView), BooleanBoxes.TrueBox, propertyChanged: OnIsRefreshEnabledPropertyChanged, coerceValue: CoerceIsRefreshEnabledProperty); bool _isRefreshEnabledExplicit = (bool)IsRefreshEnabledProperty.DefaultValue; @@ -173,7 +173,7 @@ public IPlatformElementConfiguration On() where T : IConfigPl object ICommandElement.CommandParameter => CommandParameter; protected override bool IsEnabledCore => base.IsEnabledCore; - + void ICommandElement.CanExecuteChanged(object sender, EventArgs e) { if (IsRefreshing) diff --git a/src/Controls/src/Core/Shell/Shell.cs b/src/Controls/src/Core/Shell/Shell.cs index 849f6a890fff..2c048ee3998f 100644 --- a/src/Controls/src/Core/Shell/Shell.cs +++ b/src/Controls/src/Core/Shell/Shell.cs @@ -88,7 +88,7 @@ private static void OnNavBarIsVisibleChanged(BindableObject bindable, object old { // Notify about the property change shell.OnPropertyChanged(NavBarIsVisibleProperty.PropertyName); - + if (shell == null) { return; @@ -172,7 +172,7 @@ static void OnSearchHandlerPropertyChanged(BindableObject bindable, object oldVa /// /// The object that sets the visibility of flyout items. /// to set the flyout item as visible; otherwise, . - public static void SetFlyoutItemIsVisible(BindableObject obj, bool isVisible) => obj.SetValue(FlyoutItemIsVisibleProperty, isVisible); + public static void SetFlyoutItemIsVisible(BindableObject obj, bool isVisible) => obj.SetValue(FlyoutItemIsVisibleProperty, BooleanBoxes.Box(isVisible)); static void OnFlyoutItemIsVisibleChanged(BindableObject bindable, object oldValue, object newValue) { @@ -1846,8 +1846,8 @@ void SendNavigating(ShellNavigatingEventArgs args) // correctly reflects the destination page at that point. _previousPage = CurrentPage; } - - // Unsubscribe Loaded handler if navigating away before page loads to prevent memory leaks. + + // Unsubscribe Loaded handler if navigating away before page loads to prevent memory leaks. if (CurrentPage != null && !CurrentPage.IsLoadedFired) { CurrentPage.Loaded -= OnCurrentPageLoaded; From e7c2b54e72d4c82f0f6127fa50affe42281e2a72 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Thu, 11 Jun 2026 18:25:41 -0300 Subject: [PATCH 10/11] Route bool property setters through BooleanBoxes.Box(value) to avoid boxing All public bool property setters that previously called SetValue(Prop, value) now call SetValue(Prop, BooleanBoxes.Box(value)) to eliminate per-assignment heap allocations. This completes the boxing optimization across: - VisualElement (IsVisible, IsEnabled, InputTransparent, IsFocused) - CheckBox, Switch, RadioButton (IsChecked, IsToggled) - ActivityIndicator, RefreshView, ListView, CarouselView, and others - SetterSpecificity overloads (FromHandler) also updated Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Core/ActivityIndicator/ActivityIndicator.cs | 2 +- src/Controls/src/Core/AppLinkEntry.cs | 2 +- src/Controls/src/Core/Cells/Cell.cs | 2 +- src/Controls/src/Core/Cells/SwitchCell.cs | 2 +- src/Controls/src/Core/CheckBox/CheckBox.cs | 4 ++-- src/Controls/src/Core/ContentPage/ContentPage.cs | 2 +- .../src/Core/DragAndDrop/DragGestureRecognizer.cs | 2 +- .../src/Core/DragAndDrop/DropGestureRecognizer.cs | 2 +- src/Controls/src/Core/Entry/Entry.cs | 2 +- src/Controls/src/Core/FlyoutPage/FlyoutPage.cs | 4 ++-- src/Controls/src/Core/FontImageSource.cs | 2 +- src/Controls/src/Core/Frame/Frame.cs | 2 +- .../Handlers/Shell/Tizen/ShellContentItemView.cs | 2 +- .../Handlers/Shell/Tizen/ShellFlyoutItemView.cs | 2 +- .../Handlers/Shell/Tizen/ShellSectionItemView.cs | 2 +- .../src/Core/IndicatorView/IndicatorView.cs | 2 +- src/Controls/src/Core/InputView/InputView.cs | 8 ++++---- src/Controls/src/Core/Items/CarouselView.cs | 8 ++++---- src/Controls/src/Core/Items/GroupableItemsView.cs | 2 +- .../src/Core/Items/ReorderableItemsView.cs | 4 ++-- src/Controls/src/Core/Layout/Layout.cs | 4 ++-- src/Controls/src/Core/ListView/ListView.cs | 8 ++++---- src/Controls/src/Core/Menu/MenuBar.cs | 2 +- src/Controls/src/Core/Menu/MenuBarItem.cs | 2 +- src/Controls/src/Core/Menu/MenuItem.cs | 4 ++-- src/Controls/src/Core/Page/Page.cs | 4 ++-- src/Controls/src/Core/RadioButton/RadioButton.cs | 6 +++--- src/Controls/src/Core/RefreshView/RefreshView.cs | 6 +++--- src/Controls/src/Core/Shapes/ArcSegment.cs | 2 +- src/Controls/src/Core/Shapes/PathFigure.cs | 4 ++-- src/Controls/src/Core/Shell/BackButtonBehavior.cs | 2 +- src/Controls/src/Core/Shell/BaseShellItem.cs | 6 +++--- src/Controls/src/Core/Shell/SearchHandler.cs | 14 +++++++------- src/Controls/src/Core/Shell/Shell.cs | 2 +- src/Controls/src/Core/StateTrigger.cs | 2 +- src/Controls/src/Core/SwipeView/SwipeItem.cs | 2 +- src/Controls/src/Core/Switch/Switch.cs | 4 ++-- .../src/Core/TabbedPage/TabbedPage.Tizen.cs | 2 +- src/Controls/src/Core/TableView/TableView.cs | 2 +- src/Controls/src/Core/UriImageSource.cs | 2 +- .../src/Core/VisualElement/VisualElement.cs | 8 ++++---- 41 files changed, 73 insertions(+), 73 deletions(-) diff --git a/src/Controls/src/Core/ActivityIndicator/ActivityIndicator.cs b/src/Controls/src/Core/ActivityIndicator/ActivityIndicator.cs index 7fb95a20c5a4..a309ea345192 100644 --- a/src/Controls/src/Core/ActivityIndicator/ActivityIndicator.cs +++ b/src/Controls/src/Core/ActivityIndicator/ActivityIndicator.cs @@ -49,7 +49,7 @@ public Color Color public bool IsRunning { get { return (bool)GetValue(IsRunningProperty); } - set { SetValue(IsRunningProperty, value); } + set { SetValue(IsRunningProperty, BooleanBoxes.Box(value)); } } /// diff --git a/src/Controls/src/Core/AppLinkEntry.cs b/src/Controls/src/Core/AppLinkEntry.cs index b748460c20e2..4b1a7be34aa2 100644 --- a/src/Controls/src/Core/AppLinkEntry.cs +++ b/src/Controls/src/Core/AppLinkEntry.cs @@ -50,7 +50,7 @@ public string Description public bool IsLinkActive { get { return (bool)GetValue(IsLinkActiveProperty); } - set { SetValue(IsLinkActiveProperty, value); } + set { SetValue(IsLinkActiveProperty, BooleanBoxes.Box(value)); } } /// Gets a dictionary of application-specific key-value pairs. diff --git a/src/Controls/src/Core/Cells/Cell.cs b/src/Controls/src/Core/Cells/Cell.cs index d03c10f5bde6..ae98ac6b1be9 100644 --- a/src/Controls/src/Core/Cells/Cell.cs +++ b/src/Controls/src/Core/Cells/Cell.cs @@ -130,7 +130,7 @@ public double Height public bool IsEnabled { get { return (bool)GetValue(IsEnabledProperty); } - set { SetValue(IsEnabledProperty, value); } + set { SetValue(IsEnabledProperty, BooleanBoxes.Box(value)); } } /// Gets the height of the rendered cell on the device. diff --git a/src/Controls/src/Core/Cells/SwitchCell.cs b/src/Controls/src/Core/Cells/SwitchCell.cs index 7eb0df884874..14fe18f11e74 100644 --- a/src/Controls/src/Core/Cells/SwitchCell.cs +++ b/src/Controls/src/Core/Cells/SwitchCell.cs @@ -33,7 +33,7 @@ public Color OnColor public bool On { get { return (bool)GetValue(OnProperty); } - set { SetValue(OnProperty, value); } + set { SetValue(OnProperty, BooleanBoxes.Box(value)); } } /// Gets or sets the text displayed next to the switch. This is a bindable property. diff --git a/src/Controls/src/Core/CheckBox/CheckBox.cs b/src/Controls/src/Core/CheckBox/CheckBox.cs index 5fd88fe31b1f..936a78d49a89 100644 --- a/src/Controls/src/Core/CheckBox/CheckBox.cs +++ b/src/Controls/src/Core/CheckBox/CheckBox.cs @@ -98,7 +98,7 @@ public Color Color public bool IsChecked { get => (bool)GetValue(IsCheckedProperty); - set => SetValue(IsCheckedProperty, value); + set => SetValue(IsCheckedProperty, BooleanBoxes.Box(value)); } protected internal override void ChangeVisualState() @@ -175,7 +175,7 @@ void ICommandElement.CanExecuteChanged(object sender, EventArgs e) => bool ICheckBox.IsChecked { get => IsChecked; - set => SetValue(IsCheckedProperty, value, SetterSpecificity.FromHandler); + set => SetValue(IsCheckedProperty, BooleanBoxes.Box(value), SetterSpecificity.FromHandler); } ICommand ICommandElement.Command => Command; diff --git a/src/Controls/src/Core/ContentPage/ContentPage.cs b/src/Controls/src/Core/ContentPage/ContentPage.cs index 50a8f6367d7c..b0dd5083cd28 100644 --- a/src/Controls/src/Core/ContentPage/ContentPage.cs +++ b/src/Controls/src/Core/ContentPage/ContentPage.cs @@ -39,7 +39,7 @@ public static readonly BindableProperty HideSoftInputOnTappedProperty public bool HideSoftInputOnTapped { get { return (bool)GetValue(HideSoftInputOnTappedProperty); } - set { SetValue(HideSoftInputOnTappedProperty, value); } + set { SetValue(HideSoftInputOnTappedProperty, BooleanBoxes.Box(value)); } } /// diff --git a/src/Controls/src/Core/DragAndDrop/DragGestureRecognizer.cs b/src/Controls/src/Core/DragAndDrop/DragGestureRecognizer.cs index 657724952931..cc259ed4ae46 100644 --- a/src/Controls/src/Core/DragAndDrop/DragGestureRecognizer.cs +++ b/src/Controls/src/Core/DragAndDrop/DragGestureRecognizer.cs @@ -53,7 +53,7 @@ public DragGestureRecognizer() public bool CanDrag { get { return (bool)GetValue(CanDragProperty); } - set { SetValue(CanDragProperty, value); } + set { SetValue(CanDragProperty, BooleanBoxes.Box(value)); } } /// diff --git a/src/Controls/src/Core/DragAndDrop/DropGestureRecognizer.cs b/src/Controls/src/Core/DragAndDrop/DropGestureRecognizer.cs index de5f32daccfa..fab205b483d5 100644 --- a/src/Controls/src/Core/DragAndDrop/DropGestureRecognizer.cs +++ b/src/Controls/src/Core/DragAndDrop/DropGestureRecognizer.cs @@ -63,7 +63,7 @@ public DropGestureRecognizer() public bool AllowDrop { get { return (bool)GetValue(AllowDropProperty); } - set { SetValue(AllowDropProperty, value); } + set { SetValue(AllowDropProperty, BooleanBoxes.Box(value)); } } /// diff --git a/src/Controls/src/Core/Entry/Entry.cs b/src/Controls/src/Core/Entry/Entry.cs index fd55bc9884fd..7485174dc87a 100644 --- a/src/Controls/src/Core/Entry/Entry.cs +++ b/src/Controls/src/Core/Entry/Entry.cs @@ -122,7 +122,7 @@ public TextAlignment VerticalTextAlignment public bool IsPassword { get { return (bool)GetValue(IsPasswordProperty); } - set { SetValue(IsPasswordProperty, value); } + set { SetValue(IsPasswordProperty, BooleanBoxes.Box(value)); } } /// diff --git a/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs b/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs index 6ab8266cc5cf..dd6c7c666f5e 100644 --- a/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs +++ b/src/Controls/src/Core/FlyoutPage/FlyoutPage.cs @@ -95,14 +95,14 @@ public Page Detail public bool IsGestureEnabled { get { return (bool)GetValue(IsGestureEnabledProperty); } - set { SetValue(IsGestureEnabledProperty, value); } + set { SetValue(IsGestureEnabledProperty, BooleanBoxes.Box(value)); } } /// Gets or sets a value that indicates whether the flyout is presented. This is a bindable property. public bool IsPresented { get { return (bool)GetValue(IsPresentedProperty); } - set { SetValue(IsPresentedProperty, value); } + set { SetValue(IsPresentedProperty, BooleanBoxes.Box(value)); } } /// Gets or sets the flyout page that is used to present a menu or navigation options. diff --git a/src/Controls/src/Core/FontImageSource.cs b/src/Controls/src/Core/FontImageSource.cs index 07838598be76..43a140b68578 100644 --- a/src/Controls/src/Core/FontImageSource.cs +++ b/src/Controls/src/Core/FontImageSource.cs @@ -64,7 +64,7 @@ public double Size public bool FontAutoScalingEnabled { get => (bool)GetValue(FontAutoScalingEnabledProperty); - set => SetValue(FontAutoScalingEnabledProperty, value); + set => SetValue(FontAutoScalingEnabledProperty, BooleanBoxes.Box(value)); } } } diff --git a/src/Controls/src/Core/Frame/Frame.cs b/src/Controls/src/Core/Frame/Frame.cs index c32e8393a0d2..6abbb588f6dc 100644 --- a/src/Controls/src/Core/Frame/Frame.cs +++ b/src/Controls/src/Core/Frame/Frame.cs @@ -39,7 +39,7 @@ Thickness IPaddingElement.PaddingDefaultValueCreator() public bool HasShadow { get { return (bool)GetValue(HasShadowProperty); } - set { SetValue(HasShadowProperty, value); } + set { SetValue(HasShadowProperty, BooleanBoxes.Box(value)); } } /// Gets or sets the border color for the frame. This is a bindable property. diff --git a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellContentItemView.cs b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellContentItemView.cs index 3b22385793eb..bca023fa734d 100644 --- a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellContentItemView.cs +++ b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellContentItemView.cs @@ -19,7 +19,7 @@ class ShellContentItemView : Frame public bool IsSelected { get => (bool)GetValue(SelectedStateProperty); - set => SetValue(SelectedStateProperty, value); + set => SetValue(SelectedStateProperty, BooleanBoxes.Box(value)); } diff --git a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellFlyoutItemView.cs b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellFlyoutItemView.cs index c1eb375a090f..35765a09d399 100644 --- a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellFlyoutItemView.cs +++ b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellFlyoutItemView.cs @@ -14,7 +14,7 @@ class ShellFlyoutItemView : Frame public bool IsSelected { get => (bool)GetValue(SelectedStateProperty); - set => SetValue(SelectedStateProperty, value); + set => SetValue(SelectedStateProperty, BooleanBoxes.Box(value)); } #pragma warning disable CS8618 diff --git a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellSectionItemView.cs b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellSectionItemView.cs index 310ece04914d..354b15824201 100644 --- a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellSectionItemView.cs +++ b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellSectionItemView.cs @@ -20,7 +20,7 @@ class ShellSectionItemView : Frame public bool IsSelected { get => (bool)GetValue(SelectedStateProperty); - set => SetValue(SelectedStateProperty, value); + set => SetValue(SelectedStateProperty, BooleanBoxes.Box(value)); } public GColor SelectedColor diff --git a/src/Controls/src/Core/IndicatorView/IndicatorView.cs b/src/Controls/src/Core/IndicatorView/IndicatorView.cs index 72031ca88acb..b70df42c2bc9 100644 --- a/src/Controls/src/Core/IndicatorView/IndicatorView.cs +++ b/src/Controls/src/Core/IndicatorView/IndicatorView.cs @@ -155,7 +155,7 @@ public DataTemplate IndicatorTemplate public bool HideSingle { get => (bool)GetValue(HideSingleProperty); - set => SetValue(HideSingleProperty, value); + set => SetValue(HideSingleProperty, BooleanBoxes.Box(value)); } /// diff --git a/src/Controls/src/Core/InputView/InputView.cs b/src/Controls/src/Core/InputView/InputView.cs index cccfb906fcba..e311bcb44658 100644 --- a/src/Controls/src/Core/InputView/InputView.cs +++ b/src/Controls/src/Core/InputView/InputView.cs @@ -121,7 +121,7 @@ public Keyboard Keyboard public bool IsSpellCheckEnabled { get => (bool)GetValue(IsSpellCheckEnabledProperty); - set => SetValue(IsSpellCheckEnabledProperty, value); + set => SetValue(IsSpellCheckEnabledProperty, BooleanBoxes.Box(value)); } /// Gets or sets a value that controls whether text prediction and automatic text correction are enabled. @@ -130,7 +130,7 @@ public bool IsSpellCheckEnabled public bool IsTextPredictionEnabled { get => (bool)GetValue(IsTextPredictionEnabledProperty); - set => SetValue(IsTextPredictionEnabledProperty, value); + set => SetValue(IsTextPredictionEnabledProperty, BooleanBoxes.Box(value)); } /// Gets or sets a value indicating whether the user can edit text in this input view. This is a bindable property. @@ -138,7 +138,7 @@ public bool IsTextPredictionEnabled public bool IsReadOnly { get => (bool)GetValue(IsReadOnlyProperty); - set => SetValue(IsReadOnlyProperty, value); + set => SetValue(IsReadOnlyProperty, BooleanBoxes.Box(value)); } /// Gets or sets the placeholder text shown when the input view is empty. This is a bindable property. @@ -271,7 +271,7 @@ public double FontSize public bool FontAutoScalingEnabled { get => (bool)GetValue(FontAutoScalingEnabledProperty); - set => SetValue(FontAutoScalingEnabledProperty, value); + set => SetValue(FontAutoScalingEnabledProperty, BooleanBoxes.Box(value)); } double IFontElement.FontSizeDefaultValueCreator() => diff --git a/src/Controls/src/Core/Items/CarouselView.cs b/src/Controls/src/Core/Items/CarouselView.cs index 81381d872dbd..e2f3d64eb7c8 100644 --- a/src/Controls/src/Core/Items/CarouselView.cs +++ b/src/Controls/src/Core/Items/CarouselView.cs @@ -59,7 +59,7 @@ public class CarouselView : ItemsView public bool Loop { get { return (bool)GetValue(LoopProperty); } - set { SetValue(LoopProperty, value); } + set { SetValue(LoopProperty, BooleanBoxes.Box(value)); } } /// Bindable property for . @@ -124,7 +124,7 @@ public Thickness PeekAreaInsets public bool IsBounceEnabled { get { return (bool)GetValue(IsBounceEnabledProperty); } - set { SetValue(IsBounceEnabledProperty, value); } + set { SetValue(IsBounceEnabledProperty, BooleanBoxes.Box(value)); } } /// Bindable property for . @@ -142,7 +142,7 @@ public bool IsBounceEnabled public bool IsSwipeEnabled { get { return (bool)GetValue(IsSwipeEnabledProperty); } - set { SetValue(IsSwipeEnabledProperty, value); } + set { SetValue(IsSwipeEnabledProperty, BooleanBoxes.Box(value)); } } /// Bindable property for . @@ -160,7 +160,7 @@ public bool IsSwipeEnabled public bool IsScrollAnimated { get { return (bool)GetValue(IsScrollAnimatedProperty); } - set { SetValue(IsScrollAnimatedProperty, value); } + set { SetValue(IsScrollAnimatedProperty, BooleanBoxes.Box(value)); } } /// Bindable property for . diff --git a/src/Controls/src/Core/Items/GroupableItemsView.cs b/src/Controls/src/Core/Items/GroupableItemsView.cs index 8cd6bce89c1f..d96fa6a7d227 100644 --- a/src/Controls/src/Core/Items/GroupableItemsView.cs +++ b/src/Controls/src/Core/Items/GroupableItemsView.cs @@ -27,7 +27,7 @@ public class GroupableItemsView : SelectableItemsView public bool IsGrouped { get => (bool)GetValue(IsGroupedProperty); - set => SetValue(IsGroupedProperty, value); + set => SetValue(IsGroupedProperty, BooleanBoxes.Box(value)); } /// Bindable property for . diff --git a/src/Controls/src/Core/Items/ReorderableItemsView.cs b/src/Controls/src/Core/Items/ReorderableItemsView.cs index ff2722bb7510..a263427f4d04 100644 --- a/src/Controls/src/Core/Items/ReorderableItemsView.cs +++ b/src/Controls/src/Core/Items/ReorderableItemsView.cs @@ -39,7 +39,7 @@ public class ReorderableItemsView : GroupableItemsView public bool CanMixGroups { get { return (bool)GetValue(CanMixGroupsProperty); } - set { SetValue(CanMixGroupsProperty, value); } + set { SetValue(CanMixGroupsProperty, BooleanBoxes.Box(value)); } } /// Bindable property for . @@ -57,7 +57,7 @@ public bool CanMixGroups public bool CanReorderItems { get { return (bool)GetValue(CanReorderItemsProperty); } - set { SetValue(CanReorderItemsProperty, value); } + set { SetValue(CanReorderItemsProperty, BooleanBoxes.Box(value)); } } [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/Controls/src/Core/Layout/Layout.cs b/src/Controls/src/Core/Layout/Layout.cs index 89ad7c3d0a1d..df6c45237cdf 100644 --- a/src/Controls/src/Core/Layout/Layout.cs +++ b/src/Controls/src/Core/Layout/Layout.cs @@ -97,7 +97,7 @@ public IView this[int index] public bool IsClippedToBounds { get => (bool)GetValue(IsClippedToBoundsProperty); - set => SetValue(IsClippedToBoundsProperty, value); + set => SetValue(IsClippedToBoundsProperty, BooleanBoxes.Box(value)); } static void IsClippedToBoundsPropertyChanged(BindableObject bindableObject, object oldValue, object newValue) @@ -400,7 +400,7 @@ public Graphics.Size CrossPlatformArrange(Graphics.Rect bounds) public bool CascadeInputTransparent { get => (bool)GetValue(CascadeInputTransparentProperty); - set => SetValue(CascadeInputTransparentProperty, value); + set => SetValue(CascadeInputTransparentProperty, BooleanBoxes.Box(value)); } private protected override string GetDebuggerDisplay() diff --git a/src/Controls/src/Core/ListView/ListView.cs b/src/Controls/src/Core/ListView/ListView.cs index c7cbf0d488a3..9521cc50dc75 100644 --- a/src/Controls/src/Core/ListView/ListView.cs +++ b/src/Controls/src/Core/ListView/ListView.cs @@ -209,7 +209,7 @@ public BindingBase GroupShortNameBinding public bool HasUnevenRows { get { return (bool)GetValue(HasUnevenRowsProperty); } - set { SetValue(HasUnevenRowsProperty, value); } + set { SetValue(HasUnevenRowsProperty, BooleanBoxes.Box(value)); } } /// Gets or sets the string, binding, or view that will be displayed at the top of the list view. This is a bindable property. @@ -230,21 +230,21 @@ public DataTemplate HeaderTemplate public bool IsGroupingEnabled { get { return (bool)GetValue(IsGroupingEnabledProperty); } - set { SetValue(IsGroupingEnabledProperty, value); } + set { SetValue(IsGroupingEnabledProperty, BooleanBoxes.Box(value)); } } /// Gets or sets a value that tells whether the user can swipe down to cause the application to refresh. This is a bindable property. public bool IsPullToRefreshEnabled { get { return (bool)GetValue(IsPullToRefreshEnabledProperty); } - set { SetValue(IsPullToRefreshEnabledProperty, value); } + set { SetValue(IsPullToRefreshEnabledProperty, BooleanBoxes.Box(value)); } } /// Gets or sets a value that tells whether the list view is currently refreshing. This is a bindable property. public bool IsRefreshing { get { return (bool)GetValue(IsRefreshingProperty); } - set { SetValue(IsRefreshingProperty, value); } + set { SetValue(IsRefreshingProperty, BooleanBoxes.Box(value)); } } /// Gets or sets the command that is run when the list view enters the refreshing state. This is a bindable property. diff --git a/src/Controls/src/Core/Menu/MenuBar.cs b/src/Controls/src/Core/Menu/MenuBar.cs index 5da4d714ce37..d589c6dea833 100644 --- a/src/Controls/src/Core/Menu/MenuBar.cs +++ b/src/Controls/src/Core/Menu/MenuBar.cs @@ -16,7 +16,7 @@ public partial class MenuBar : Element, IMenuBar public bool IsEnabled { get { return (bool)GetValue(IsEnabledProperty); } - set { SetValue(IsEnabledProperty, value); } + set { SetValue(IsEnabledProperty, BooleanBoxes.Box(value)); } } readonly ObservableCollection _menus = new ObservableCollection(); diff --git a/src/Controls/src/Core/Menu/MenuBarItem.cs b/src/Controls/src/Core/Menu/MenuBarItem.cs index b1dcbbd0f6fb..33f3396ed31d 100644 --- a/src/Controls/src/Core/Menu/MenuBarItem.cs +++ b/src/Controls/src/Core/Menu/MenuBarItem.cs @@ -32,7 +32,7 @@ public int Priority public bool IsEnabled { get { return (bool)GetValue(IsEnabledProperty); } - set { SetValue(IsEnabledProperty, value); } + set { SetValue(IsEnabledProperty, BooleanBoxes.Box(value)); } } public string Text diff --git a/src/Controls/src/Core/Menu/MenuItem.cs b/src/Controls/src/Core/Menu/MenuItem.cs index f608a3338622..4d9ecf8dd9b3 100644 --- a/src/Controls/src/Core/Menu/MenuItem.cs +++ b/src/Controls/src/Core/Menu/MenuItem.cs @@ -86,7 +86,7 @@ public ImageSource IconImageSource public bool IsDestructive { get => (bool)GetValue(IsDestructiveProperty); - set => SetValue(IsDestructiveProperty, value); + set => SetValue(IsDestructiveProperty, BooleanBoxes.Box(value)); } /// The text of the menu item. This is a bindable property. @@ -100,7 +100,7 @@ public string Text public bool IsEnabled { get => (bool)GetValue(IsEnabledProperty); - set => SetValue(IsEnabledProperty, value); + set => SetValue(IsEnabledProperty, BooleanBoxes.Box(value)); } public event EventHandler Clicked; diff --git a/src/Controls/src/Core/Page/Page.cs b/src/Controls/src/Core/Page/Page.cs index 24d1fcfeac84..aea36bdbfd5b 100644 --- a/src/Controls/src/Core/Page/Page.cs +++ b/src/Controls/src/Core/Page/Page.cs @@ -129,7 +129,7 @@ public ImageSource IconImageSource public bool IsBusy { get { return (bool)GetValue(IsBusyProperty); } - set { SetValue(IsBusyProperty, value); } + set { SetValue(IsBusyProperty, BooleanBoxes.Box(value)); } } /// @@ -197,7 +197,7 @@ public Rect ContainerArea public bool IgnoresContainerArea { get { return (bool)GetValue(IgnoresContainerAreaProperty); } - set { SetValue(IgnoresContainerAreaProperty, value); } + set { SetValue(IgnoresContainerAreaProperty, BooleanBoxes.Box(value)); } } /// diff --git a/src/Controls/src/Core/RadioButton/RadioButton.cs b/src/Controls/src/Core/RadioButton/RadioButton.cs index df03d73e20a1..fccaaf3004b6 100644 --- a/src/Controls/src/Core/RadioButton/RadioButton.cs +++ b/src/Controls/src/Core/RadioButton/RadioButton.cs @@ -165,7 +165,7 @@ public object Value public bool IsChecked { get { return (bool)GetValue(IsCheckedProperty); } - set { SetValue(IsCheckedProperty, value); } + set { SetValue(IsCheckedProperty, BooleanBoxes.Box(value)); } } /// @@ -254,7 +254,7 @@ public double FontSize public bool FontAutoScalingEnabled { get => (bool)GetValue(FontAutoScalingEnabledProperty); - set => SetValue(FontAutoScalingEnabledProperty, value); + set => SetValue(FontAutoScalingEnabledProperty, BooleanBoxes.Box(value)); } /// @@ -752,7 +752,7 @@ object IContentView.Content bool IRadioButton.IsChecked { get => IsChecked; - set => SetValue(IsCheckedProperty, value, SetterSpecificity.FromHandler); + set => SetValue(IsCheckedProperty, BooleanBoxes.Box(value), SetterSpecificity.FromHandler); } private protected override string GetDebuggerDisplay() diff --git a/src/Controls/src/Core/RefreshView/RefreshView.cs b/src/Controls/src/Core/RefreshView/RefreshView.cs index 62eaf19a7962..caccf5fd1bfb 100644 --- a/src/Controls/src/Core/RefreshView/RefreshView.cs +++ b/src/Controls/src/Core/RefreshView/RefreshView.cs @@ -72,7 +72,7 @@ static object OnIsRefreshingPropertyCoerced(BindableObject bindable, object valu public bool IsRefreshing { get { return (bool)GetValue(IsRefreshingProperty); } - set { SetValue(IsRefreshingProperty, value); } + set { SetValue(IsRefreshingProperty, BooleanBoxes.Box(value)); } } /// Bindable property for . @@ -157,7 +157,7 @@ static void OnIsRefreshEnabledPropertyChanged(BindableObject bindable, object ol public bool IsRefreshEnabled { get { return (bool)GetValue(IsRefreshEnabledProperty); } - set { SetValue(IsRefreshEnabledProperty, value); } + set { SetValue(IsRefreshEnabledProperty, BooleanBoxes.Box(value)); } } /// @@ -201,7 +201,7 @@ protected override void OnPropertyChanged([CallerMemberName] string propertyName bool IRefreshView.IsRefreshing { get => IsRefreshing; - set { SetValue(IsRefreshingProperty, value, SetterSpecificity.FromHandler); } + set { SetValue(IsRefreshingProperty, BooleanBoxes.Box(value), SetterSpecificity.FromHandler); } } private protected override string GetDebuggerDisplay() diff --git a/src/Controls/src/Core/Shapes/ArcSegment.cs b/src/Controls/src/Core/Shapes/ArcSegment.cs index 9ad77d58cdde..ce0698750c7c 100644 --- a/src/Controls/src/Core/Shapes/ArcSegment.cs +++ b/src/Controls/src/Core/Shapes/ArcSegment.cs @@ -97,7 +97,7 @@ public SweepDirection SweepDirection /// public bool IsLargeArc { - set { SetValue(IsLargeArcProperty, value); } + set { SetValue(IsLargeArcProperty, BooleanBoxes.Box(value)); } get { return (bool)GetValue(IsLargeArcProperty); } } } diff --git a/src/Controls/src/Core/Shapes/PathFigure.cs b/src/Controls/src/Core/Shapes/PathFigure.cs index c2ca9626b263..56ee4d2e6a5e 100644 --- a/src/Controls/src/Core/Shapes/PathFigure.cs +++ b/src/Controls/src/Core/Shapes/PathFigure.cs @@ -66,7 +66,7 @@ public Point StartPoint /// public bool IsClosed { - set { SetValue(IsClosedProperty, value); } + set { SetValue(IsClosedProperty, BooleanBoxes.Box(value)); } get { return (bool)GetValue(IsClosedProperty); } } @@ -75,7 +75,7 @@ public bool IsClosed /// public bool IsFilled { - set { SetValue(IsFilledProperty, value); } + set { SetValue(IsFilledProperty, BooleanBoxes.Box(value)); } get { return (bool)GetValue(IsFilledProperty); } } diff --git a/src/Controls/src/Core/Shell/BackButtonBehavior.cs b/src/Controls/src/Core/Shell/BackButtonBehavior.cs index e8da835d7573..67b037ec99b7 100644 --- a/src/Controls/src/Core/Shell/BackButtonBehavior.cs +++ b/src/Controls/src/Core/Shell/BackButtonBehavior.cs @@ -87,7 +87,7 @@ public bool IsEnabled public bool IsVisible { get { return (bool)GetValue(IsVisibleProperty); } - set { SetValue(IsVisibleProperty, value); } + set { SetValue(IsVisibleProperty, BooleanBoxes.Box(value)); } } /// diff --git a/src/Controls/src/Core/Shell/BaseShellItem.cs b/src/Controls/src/Core/Shell/BaseShellItem.cs index a75414074ee3..6b6e3d602503 100644 --- a/src/Controls/src/Core/Shell/BaseShellItem.cs +++ b/src/Controls/src/Core/Shell/BaseShellItem.cs @@ -106,7 +106,7 @@ public ImageSource Icon public bool IsEnabled { get { return (bool)GetValue(IsEnabledProperty); } - set { SetValue(IsEnabledProperty, value); } + set { SetValue(IsEnabledProperty, BooleanBoxes.Box(value)); } } /// @@ -137,7 +137,7 @@ public string Title public bool IsVisible { get => (bool)GetValue(IsVisibleProperty); - set => SetValue(IsVisibleProperty, value); + set => SetValue(IsVisibleProperty, BooleanBoxes.Box(value)); } /// @@ -146,7 +146,7 @@ public bool IsVisible public bool FlyoutItemIsVisible { get => (bool)GetValue(FlyoutItemIsVisibleProperty); - set => SetValue(FlyoutItemIsVisibleProperty, value); + set => SetValue(FlyoutItemIsVisibleProperty, BooleanBoxes.Box(value)); } diff --git a/src/Controls/src/Core/Shell/SearchHandler.cs b/src/Controls/src/Core/Shell/SearchHandler.cs index 61dc0d811c2a..5bf0d6cbcd78 100644 --- a/src/Controls/src/Core/Shell/SearchHandler.cs +++ b/src/Controls/src/Core/Shell/SearchHandler.cs @@ -62,7 +62,7 @@ static void OnIsFocusedPropertyChanged(BindableObject bindable, object oldvalue, [EditorBrowsable(EditorBrowsableState.Never)] public void SetIsFocused(bool value) { - SetValue(IsFocusedPropertyKey, value, specificity: SetterSpecificity.FromHandler); + SetValue(IsFocusedPropertyKey, BooleanBoxes.Box(value), specificity: SetterSpecificity.FromHandler); } [EditorBrowsable(EditorBrowsableState.Never)] public event EventHandler FocusChangeRequested; @@ -237,7 +237,7 @@ public double FontSize public bool FontAutoScalingEnabled { get => (bool)GetValue(FontAutoScalingEnabledProperty); - set => SetValue(FontAutoScalingEnabledProperty, value); + set => SetValue(FontAutoScalingEnabledProperty, BooleanBoxes.Box(value)); } void IFontElement.OnFontFamilyChanged(string oldValue, string newValue) @@ -484,7 +484,7 @@ public object ClearPlaceholderCommandParameter public bool ClearPlaceholderEnabled { get { return (bool)GetValue(ClearPlaceholderEnabledProperty); } - set { SetValue(ClearPlaceholderEnabledProperty, value); } + set { SetValue(ClearPlaceholderEnabledProperty, BooleanBoxes.Box(value)); } } /// Gets or sets the accessibility help text for the clear placeholder icon. This is a bindable property. @@ -534,7 +534,7 @@ public string DisplayMemberName public bool IsSearchEnabled { get { return (bool)GetValue(IsSearchEnabledProperty); } - set { SetValue(IsSearchEnabledProperty, value); } + set { SetValue(IsSearchEnabledProperty, BooleanBoxes.Box(value)); } } /// Gets or sets the collection of items to display as search suggestions. This is a bindable property. @@ -593,12 +593,12 @@ public SearchBoxVisibility SearchBoxVisibility public bool ShowsResults { get { return (bool)GetValue(ShowsResultsProperty); } - set { SetValue(ShowsResultsProperty, value); } + set { SetValue(ShowsResultsProperty, BooleanBoxes.Box(value)); } } - bool ClearPlaceholderEnabledCore { set => SetValue(ClearPlaceholderEnabledProperty, value); } + bool ClearPlaceholderEnabledCore { set => SetValue(ClearPlaceholderEnabledProperty, BooleanBoxes.Box(value)); } - bool IsSearchEnabledCore { set => SetValue(IsSearchEnabledProperty, value); } + bool IsSearchEnabledCore { set => SetValue(IsSearchEnabledProperty, BooleanBoxes.Box(value)); } protected virtual void OnClearPlaceholderClicked() { diff --git a/src/Controls/src/Core/Shell/Shell.cs b/src/Controls/src/Core/Shell/Shell.cs index 2c048ee3998f..7e0f6786752f 100644 --- a/src/Controls/src/Core/Shell/Shell.cs +++ b/src/Controls/src/Core/Shell/Shell.cs @@ -1620,7 +1620,7 @@ public DataTemplate FlyoutFooterTemplate public bool FlyoutIsPresented { get => (bool)GetValue(FlyoutIsPresentedProperty); - set => SetValue(FlyoutIsPresentedProperty, value); + set => SetValue(FlyoutIsPresentedProperty, BooleanBoxes.Box(value)); } /// Gets the collection of objects in the Shell. This is a bindable property. diff --git a/src/Controls/src/Core/StateTrigger.cs b/src/Controls/src/Core/StateTrigger.cs index fa2700390109..aba72ff65b21 100644 --- a/src/Controls/src/Core/StateTrigger.cs +++ b/src/Controls/src/Core/StateTrigger.cs @@ -13,7 +13,7 @@ public sealed class StateTrigger : StateTriggerBase public new bool IsActive { get => (bool)GetValue(IsActiveProperty); - set => SetValue(IsActiveProperty, value); + set => SetValue(IsActiveProperty, BooleanBoxes.Box(value)); } /// Bindable property for . diff --git a/src/Controls/src/Core/SwipeView/SwipeItem.cs b/src/Controls/src/Core/SwipeView/SwipeItem.cs index 161eec8b6cb7..9280923edb47 100644 --- a/src/Controls/src/Core/SwipeView/SwipeItem.cs +++ b/src/Controls/src/Core/SwipeView/SwipeItem.cs @@ -32,7 +32,7 @@ public Color BackgroundColor public bool IsVisible { get { return (bool)GetValue(IsVisibleProperty); } - set { SetValue(IsVisibleProperty, value); } + set { SetValue(IsVisibleProperty, BooleanBoxes.Box(value)); } } public event EventHandler Invoked; diff --git a/src/Controls/src/Core/Switch/Switch.cs b/src/Controls/src/Core/Switch/Switch.cs index 8aa4eb545076..916e945a143e 100644 --- a/src/Controls/src/Core/Switch/Switch.cs +++ b/src/Controls/src/Core/Switch/Switch.cs @@ -107,7 +107,7 @@ public Switch() public bool IsToggled { get { return (bool)GetValue(IsToggledProperty); } - set { SetValue(IsToggledProperty, value); } + set { SetValue(IsToggledProperty, BooleanBoxes.Box(value)); } } protected internal override void ChangeVisualState() @@ -157,7 +157,7 @@ Color ISwitch.TrackColor bool ISwitch.IsOn { get => IsToggled; - set => SetValue(IsToggledProperty, value, SetterSpecificity.FromHandler); + set => SetValue(IsToggledProperty, BooleanBoxes.Box(value), SetterSpecificity.FromHandler); } private protected override string GetDebuggerDisplay() diff --git a/src/Controls/src/Core/TabbedPage/TabbedPage.Tizen.cs b/src/Controls/src/Core/TabbedPage/TabbedPage.Tizen.cs index adda351e7440..2b22f191c78e 100644 --- a/src/Controls/src/Core/TabbedPage/TabbedPage.Tizen.cs +++ b/src/Controls/src/Core/TabbedPage/TabbedPage.Tizen.cs @@ -174,7 +174,7 @@ class TabbedItem : Frame public bool IsSelected { get => (bool)GetValue(SelectedStateProperty); - set => SetValue(SelectedStateProperty, value); + set => SetValue(SelectedStateProperty, BooleanBoxes.Box(value)); } public GColor SelectedTabColor diff --git a/src/Controls/src/Core/TableView/TableView.cs b/src/Controls/src/Core/TableView/TableView.cs index 3e891fa4bc17..a5ee334b70f3 100644 --- a/src/Controls/src/Core/TableView/TableView.cs +++ b/src/Controls/src/Core/TableView/TableView.cs @@ -57,7 +57,7 @@ public TableView(TableRoot root) public bool HasUnevenRows { get { return (bool)GetValue(HasUnevenRowsProperty); } - set { SetValue(HasUnevenRowsProperty, value); } + set { SetValue(HasUnevenRowsProperty, BooleanBoxes.Box(value)); } } /// diff --git a/src/Controls/src/Core/UriImageSource.cs b/src/Controls/src/Core/UriImageSource.cs index 5ce1935445e5..8f4130182b7b 100644 --- a/src/Controls/src/Core/UriImageSource.cs +++ b/src/Controls/src/Core/UriImageSource.cs @@ -41,7 +41,7 @@ public TimeSpan CacheValidity public bool CachingEnabled { get => (bool)GetValue(CachingEnabledProperty); - set => SetValue(CachingEnabledProperty, value); + set => SetValue(CachingEnabledProperty, BooleanBoxes.Box(value)); } /// Gets or sets the URI of the image to load. This is a bindable property. diff --git a/src/Controls/src/Core/VisualElement/VisualElement.cs b/src/Controls/src/Core/VisualElement/VisualElement.cs index 9c84bea7165f..2dc29950cdbf 100644 --- a/src/Controls/src/Core/VisualElement/VisualElement.cs +++ b/src/Controls/src/Core/VisualElement/VisualElement.cs @@ -642,7 +642,7 @@ public double HeightRequest public bool InputTransparent { get { return (bool)GetValue(InputTransparentProperty); } - set { SetValue(InputTransparentProperty, value); } + set { SetValue(InputTransparentProperty, BooleanBoxes.Box(value)); } } /// @@ -655,7 +655,7 @@ public bool InputTransparent public bool IsEnabled { get { return (bool)GetValue(IsEnabledProperty); } - set { SetValue(IsEnabledProperty, value); } + set { SetValue(IsEnabledProperty, BooleanBoxes.Box(value)); } } /// @@ -728,7 +728,7 @@ private protected bool InputTransparentCore public bool IsVisible { get { return (bool)GetValue(IsVisibleProperty); } - set { SetValue(IsVisibleProperty, value); } + set { SetValue(IsVisibleProperty, BooleanBoxes.Box(value)); } } /// @@ -2105,7 +2105,7 @@ protected virtual Size MeasureOverride(double widthConstraint, double heightCons bool IView.IsFocused { get => (bool)GetValue(IsFocusedProperty); - set => SetValue(IsFocusedPropertyKey, value, SetterSpecificity.FromHandler); + set => SetValue(IsFocusedPropertyKey, BooleanBoxes.Box(value), SetterSpecificity.FromHandler); } /// From f0dbf63a2e81c6a0c504783fcac7c50092eb7f85 Mon Sep 17 00:00:00 2001 From: Pedro Jesus Date: Thu, 11 Jun 2026 18:30:43 -0300 Subject: [PATCH 11/11] Add production regression tests and fix coerce functions boxing - Add BooleanBoxesProductionTests class with Assert.Same checks on: * DefaultValue for representative BindableProperties * GetValue() after setter calls (verifies cached box is stored) - Fix CoerceIsEnabledProperty and CoerceInputTransparentProperty in VisualElement to return BooleanBoxes.Box(...) / BooleanBoxes.FalseBox instead of raw bool literals (which would allocate a new box) - Fix CoerceIsEnabledProperty in MenuItem similarly Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- src/Controls/src/Core/Menu/MenuItem.cs | 10 +- .../src/Core/VisualElement/VisualElement.cs | 8 +- .../tests/Core.UnitTests/BooleanBoxesTests.cs | 134 ++++++++++++++++++ 3 files changed, 143 insertions(+), 9 deletions(-) diff --git a/src/Controls/src/Core/Menu/MenuItem.cs b/src/Controls/src/Core/Menu/MenuItem.cs index 4d9ecf8dd9b3..db968e547be0 100644 --- a/src/Controls/src/Core/Menu/MenuItem.cs +++ b/src/Controls/src/Core/Menu/MenuItem.cs @@ -122,7 +122,7 @@ static object CoerceIsEnabledProperty(BindableObject bindable, object value) { if (bindable is not MenuItem menuItem) { - return false; + return BooleanBoxes.FalseBox; } menuItem._isEnabledExplicit = (bool)value; @@ -130,23 +130,23 @@ static object CoerceIsEnabledProperty(BindableObject bindable, object value) if (!menuItem._isEnabledExplicit) { // No need to check GetCanExecute or the Parent's state - return false; + return BooleanBoxes.FalseBox; } var canExecute = CommandElement.GetCanExecute(menuItem, CommandProperty); if (!canExecute) { - return false; + return BooleanBoxes.FalseBox; } // IsEnabled is not explicitly set to false, and the command can be // executed. The only thing left to verify is Parent.IsEnabled if (menuItem.Parent is MenuItem parentMenuItem && !parentMenuItem.IsEnabled) { - return false; + return BooleanBoxes.FalseBox; } - return true; + return BooleanBoxes.TrueBox; } IImageSource IImageSourcePart.Source => this.IconImageSource; diff --git a/src/Controls/src/Core/VisualElement/VisualElement.cs b/src/Controls/src/Core/VisualElement/VisualElement.cs index 2dc29950cdbf..eadfda902e1a 100644 --- a/src/Controls/src/Core/VisualElement/VisualElement.cs +++ b/src/Controls/src/Core/VisualElement/VisualElement.cs @@ -1769,10 +1769,10 @@ static object CoerceIsEnabledProperty(BindableObject bindable, object value) if (bindable is VisualElement visualElement) { visualElement._isEnabledExplicit = (bool)value; - return visualElement.IsEnabledCore; + return BooleanBoxes.Box(visualElement.IsEnabledCore); } - return false; + return BooleanBoxes.FalseBox; } static void OnIsEnabledPropertyChanged(BindableObject bindable, object oldValue, object newValue) @@ -1792,10 +1792,10 @@ static object CoerceInputTransparentProperty(BindableObject bindable, object val if (bindable is VisualElement visualElement) { visualElement._inputTransparentExplicit = (bool)value; - return visualElement.InputTransparentCore; + return BooleanBoxes.Box(visualElement.InputTransparentCore); } - return false; + return BooleanBoxes.FalseBox; } static void OnInputTransparentPropertyChanged(BindableObject bindable, object oldValue, object newValue) diff --git a/src/Controls/tests/Core.UnitTests/BooleanBoxesTests.cs b/src/Controls/tests/Core.UnitTests/BooleanBoxesTests.cs index 7cd81e786f63..39b78233d6b9 100644 --- a/src/Controls/tests/Core.UnitTests/BooleanBoxesTests.cs +++ b/src/Controls/tests/Core.UnitTests/BooleanBoxesTests.cs @@ -1,4 +1,5 @@ using Microsoft.Maui.Controls.Internals; +using Microsoft.Maui.Controls.Shapes; using Xunit; namespace Microsoft.Maui.Controls.Core.UnitTests; @@ -69,4 +70,137 @@ public void BoxReturnsSameReferenceOnRepeatedCalls() Assert.Same(BooleanBoxes.Box(true), BooleanBoxes.Box(true)); Assert.Same(BooleanBoxes.Box(false), BooleanBoxes.Box(false)); } +} + +/// +/// Regression tests that verify production BindableProperty default values and setters +/// store the shared cached boxes rather than freshly-allocated boxed booleans. +/// If any of these fail, a SetValue call site or BindableProperty default has regressed +/// to boxing instead of using BooleanBoxes. +/// +public class BooleanBoxesProductionTests : BaseTestFixture +{ + // --- DefaultValue regression tests --- + + [Fact] + public void ActivityIndicator_IsRunningProperty_DefaultValueIsFalseBox() + => Assert.Same(BooleanBoxes.FalseBox, ActivityIndicator.IsRunningProperty.DefaultValue); + + [Fact] + public void VisualElement_IsVisibleProperty_DefaultValueIsTrueBox() + => Assert.Same(BooleanBoxes.TrueBox, VisualElement.IsVisibleProperty.DefaultValue); + + [Fact] + public void VisualElement_IsEnabledProperty_DefaultValueIsTrueBox() + => Assert.Same(BooleanBoxes.TrueBox, VisualElement.IsEnabledProperty.DefaultValue); + + [Fact] + public void VisualElement_InputTransparentProperty_DefaultValueIsFalseBox() + => Assert.Same(BooleanBoxes.FalseBox, VisualElement.InputTransparentProperty.DefaultValue); + + [Fact] + public void CheckBox_IsCheckedProperty_DefaultValueIsFalseBox() + => Assert.Same(BooleanBoxes.FalseBox, CheckBox.IsCheckedProperty.DefaultValue); + + [Fact] + public void Switch_IsToggledProperty_DefaultValueIsFalseBox() + => Assert.Same(BooleanBoxes.FalseBox, Switch.IsToggledProperty.DefaultValue); + + // --- Setter regression tests: GetValue returns the cached box, not a new allocation --- + + [Fact] + public void ActivityIndicator_IsRunning_SetterStoresCachedBox() + { + var indicator = new ActivityIndicator(); + + indicator.IsRunning = true; + Assert.Same(BooleanBoxes.TrueBox, indicator.GetValue(ActivityIndicator.IsRunningProperty)); + + indicator.IsRunning = false; + Assert.Same(BooleanBoxes.FalseBox, indicator.GetValue(ActivityIndicator.IsRunningProperty)); + } + + [Fact] + public void VisualElement_IsVisible_SetterStoresCachedBox() + { + var view = new ContentView(); + + view.IsVisible = false; + Assert.Same(BooleanBoxes.FalseBox, view.GetValue(VisualElement.IsVisibleProperty)); + + view.IsVisible = true; + Assert.Same(BooleanBoxes.TrueBox, view.GetValue(VisualElement.IsVisibleProperty)); + } + + [Fact] + public void VisualElement_IsEnabled_SetterStoresCachedBox() + { + var view = new ContentView(); + + view.IsEnabled = false; + Assert.Same(BooleanBoxes.FalseBox, view.GetValue(VisualElement.IsEnabledProperty)); + + view.IsEnabled = true; + Assert.Same(BooleanBoxes.TrueBox, view.GetValue(VisualElement.IsEnabledProperty)); + } + + [Fact] + public void VisualElement_InputTransparent_SetterStoresCachedBox() + { + var view = new ContentView(); + + view.InputTransparent = true; + Assert.Same(BooleanBoxes.TrueBox, view.GetValue(VisualElement.InputTransparentProperty)); + + view.InputTransparent = false; + Assert.Same(BooleanBoxes.FalseBox, view.GetValue(VisualElement.InputTransparentProperty)); + } + + [Fact] + public void CheckBox_IsChecked_SetterStoresCachedBox() + { + var checkBox = new CheckBox(); + + checkBox.IsChecked = true; + Assert.Same(BooleanBoxes.TrueBox, checkBox.GetValue(CheckBox.IsCheckedProperty)); + + checkBox.IsChecked = false; + Assert.Same(BooleanBoxes.FalseBox, checkBox.GetValue(CheckBox.IsCheckedProperty)); + } + + [Fact] + public void Switch_IsToggled_SetterStoresCachedBox() + { + var sw = new Switch(); + + sw.IsToggled = true; + Assert.Same(BooleanBoxes.TrueBox, sw.GetValue(Switch.IsToggledProperty)); + + sw.IsToggled = false; + Assert.Same(BooleanBoxes.FalseBox, sw.GetValue(Switch.IsToggledProperty)); + } + + [Fact] + public void RefreshView_IsRefreshing_SetterStoresCachedBox() + { + var refreshView = new RefreshView(); + + refreshView.IsRefreshing = true; + Assert.Same(BooleanBoxes.TrueBox, refreshView.GetValue(RefreshView.IsRefreshingProperty)); + + refreshView.IsRefreshing = false; + Assert.Same(BooleanBoxes.FalseBox, refreshView.GetValue(RefreshView.IsRefreshingProperty)); + } + + [Fact] + public void Entry_IsPassword_SetterStoresCachedBox() + { + var entry = new Entry(); + + entry.IsPassword = true; + Assert.Same(BooleanBoxes.TrueBox, entry.GetValue(Entry.IsPasswordProperty)); + + entry.IsPassword = false; + Assert.Same(BooleanBoxes.FalseBox, entry.GetValue(Entry.IsPasswordProperty)); + } } \ No newline at end of file