diff --git a/src/Compatibility/Core/src/Android/Cells/ViewCellRenderer.cs b/src/Compatibility/Core/src/Android/Cells/ViewCellRenderer.cs index cb5717c496a5..dc359eee5fdc 100644 --- a/src/Compatibility/Core/src/Android/Cells/ViewCellRenderer.cs +++ b/src/Compatibility/Core/src/Android/Cells/ViewCellRenderer.cs @@ -206,8 +206,7 @@ public void Update(ViewCell cell) c.DisableLayout = false; var viewAsLayout = cell.View as Layout; - if (viewAsLayout != null) - viewAsLayout.ForceLayout(); + viewAsLayout?.ForceLayout(); Invalidate(); diff --git a/src/Compatibility/Core/src/Android/CollectionView/CarouselViewRenderer.cs b/src/Compatibility/Core/src/Android/CollectionView/CarouselViewRenderer.cs index 8d87772d3206..a5d31f643c5e 100644 --- a/src/Compatibility/Core/src/Android/CollectionView/CarouselViewRenderer.cs +++ b/src/Compatibility/Core/src/Android/CollectionView/CarouselViewRenderer.cs @@ -190,10 +190,7 @@ protected override void UpdateItemSpacing() var adapter = GetAdapter(); - if (adapter != null) - { - adapter.NotifyItemChanged(_oldPosition); - } + adapter?.NotifyItemChanged(_oldPosition); base.UpdateItemSpacing(); } diff --git a/src/Compatibility/Core/src/Android/Renderers/ScrollViewRenderer.cs b/src/Compatibility/Core/src/Android/Renderers/ScrollViewRenderer.cs index 8f037128de6c..a997eb066353 100644 --- a/src/Compatibility/Core/src/Android/Renderers/ScrollViewRenderer.cs +++ b/src/Compatibility/Core/src/Android/Renderers/ScrollViewRenderer.cs @@ -504,8 +504,7 @@ void UpdateOrientation() if (_container.Parent != this) { _container.RemoveFromParent(); - if (_hScrollView != null) - _hScrollView.RemoveFromParent(); + _hScrollView?.RemoveFromParent(); AddView(_container); } } diff --git a/src/Compatibility/Core/src/Tizen/Forms.cs b/src/Compatibility/Core/src/Tizen/Forms.cs index 37e729ca7310..9e323041aff2 100644 --- a/src/Compatibility/Core/src/Tizen/Forms.cs +++ b/src/Compatibility/Core/src/Tizen/Forms.cs @@ -116,14 +116,11 @@ internal static TizenTitleBarVisibility TitleBarVisibility internal static void SendViewInitialized(this VisualElement self, NView nativeView) { EventHandler viewInitialized = Forms.ViewInitialized; - if (viewInitialized != null) - { - viewInitialized.Invoke(self, new ViewInitializedEventArgs + viewInitialized?.Invoke(self, new ViewInitializedEventArgs { View = self, NativeView = nativeView }); - } } public static bool IsInitializedRenderers { get; private set; } diff --git a/src/Compatibility/Core/src/Tizen/FormsApplication.cs b/src/Compatibility/Core/src/Tizen/FormsApplication.cs index cfb45d68868b..64a96bb1b3ae 100644 --- a/src/Compatibility/Core/src/Tizen/FormsApplication.cs +++ b/src/Compatibility/Core/src/Tizen/FormsApplication.cs @@ -53,28 +53,19 @@ protected override void OnPreCreate() protected override void OnTerminate() { base.OnTerminate(); - if (_platform != null) - { - _platform.Dispose(); - } + _platform?.Dispose(); } protected override void OnPause() { base.OnPause(); - if (_application != null) - { - _application.SendSleep(); - } + _application?.SendSleep(); } protected override void OnResume() { base.OnResume(); - if (_application != null) - { - _application.SendResume(); - } + _application?.SendResume(); } [EditorBrowsable(EditorBrowsableState.Never)] diff --git a/src/Compatibility/Core/src/Tizen/Renderers/VisualElementRenderer.cs b/src/Compatibility/Core/src/Tizen/Renderers/VisualElementRenderer.cs index f590927fc7d0..b93a59d93a29 100644 --- a/src/Compatibility/Core/src/Tizen/Renderers/VisualElementRenderer.cs +++ b/src/Compatibility/Core/src/Tizen/Renderers/VisualElementRenderer.cs @@ -599,10 +599,7 @@ protected virtual void UpdateOpacity(bool initialize) /// protected virtual void OnFocused(object sender, EventArgs e) { - if (null != Element) - { - Element.SetValue(VisualElement.IsFocusedPropertyKey, true); - } + Element?.SetValue(VisualElement.IsFocusedPropertyKey, true); } /// @@ -610,10 +607,7 @@ protected virtual void OnFocused(object sender, EventArgs e) /// protected virtual void OnUnfocused(object sender, EventArgs e) { - if (null != Element) - { - Element.SetValue(VisualElement.IsFocusedPropertyKey, false); - } + Element?.SetValue(VisualElement.IsFocusedPropertyKey, false); } /// diff --git a/src/Compatibility/Core/src/Windows/CellControl.cs b/src/Compatibility/Core/src/Windows/CellControl.cs index 8438fcfae181..13575e92eae5 100644 --- a/src/Compatibility/Core/src/Windows/CellControl.cs +++ b/src/Compatibility/Core/src/Windows/CellControl.cs @@ -128,10 +128,7 @@ protected FrameworkElement CellContent // Children still need measure called on them global::Windows.Foundation.Size result = base.MeasureOverride(availableSize); - if (lv != null) - { - lv.SetValue(MeasuredEstimateProperty, result.Height); - } + lv?.SetValue(MeasuredEstimateProperty, result.Height); SetDefaultSwitchColor(); diff --git a/src/Compatibility/Core/src/Windows/FlyoutPageControl.cs b/src/Compatibility/Core/src/Windows/FlyoutPageControl.cs index 95a45e5b940c..babf4f1c460e 100644 --- a/src/Compatibility/Core/src/Windows/FlyoutPageControl.cs +++ b/src/Compatibility/Core/src/Windows/FlyoutPageControl.cs @@ -302,8 +302,7 @@ protected override void OnApplyTemplate() UpdateMode(); - if (_commandBarTcs != null) - _commandBarTcs.SetResult(_commandBar); + _commandBarTcs?.SetResult(_commandBar); _titleViewManager = new TitleViewManager(this); } diff --git a/src/Compatibility/Core/src/Windows/FlyoutPageRenderer.cs b/src/Compatibility/Core/src/Windows/FlyoutPageRenderer.cs index fe1539cf88c6..4aa7a61ee156 100644 --- a/src/Compatibility/Core/src/Windows/FlyoutPageRenderer.cs +++ b/src/Compatibility/Core/src/Windows/FlyoutPageRenderer.cs @@ -42,8 +42,7 @@ protected VisualElementTracker Tracker if (_tracker == value) return; - if (_tracker != null) - _tracker.Dispose(); + _tracker?.Dispose(); _tracker = value; } diff --git a/src/Compatibility/Core/src/Windows/ListGroupHeaderPresenter.cs b/src/Compatibility/Core/src/Windows/ListGroupHeaderPresenter.cs index e826f0c07034..619bac2b0de9 100644 --- a/src/Compatibility/Core/src/Windows/ListGroupHeaderPresenter.cs +++ b/src/Compatibility/Core/src/Windows/ListGroupHeaderPresenter.cs @@ -27,10 +27,7 @@ void OnTapped(object sender, TappedRoutedEventArgs tappedRoutedEventArgs) zoom.ToggleActiveView(); var grid = zoom.ZoomedOutView as GridView; - if (grid != null) - { - grid.MakeVisible(new SemanticZoomLocation { Item = DataContext }); - } + grid?.MakeVisible(new SemanticZoomLocation { Item = DataContext }); return; } diff --git a/src/Compatibility/Core/src/Windows/NavigationPageRenderer.cs b/src/Compatibility/Core/src/Windows/NavigationPageRenderer.cs index 017835ab299e..1c95aa29332e 100644 --- a/src/Compatibility/Core/src/Windows/NavigationPageRenderer.cs +++ b/src/Compatibility/Core/src/Windows/NavigationPageRenderer.cs @@ -48,8 +48,7 @@ protected VisualElementTracker Tracker if (_tracker == value) return; - if (_tracker != null) - _tracker.Dispose(); + _tracker?.Dispose(); _tracker = value; } diff --git a/src/Compatibility/Core/src/Windows/Platform.cs b/src/Compatibility/Core/src/Windows/Platform.cs index 4c06c76ac5e5..16f8b6605919 100644 --- a/src/Compatibility/Core/src/Windows/Platform.cs +++ b/src/Compatibility/Core/src/Windows/Platform.cs @@ -433,8 +433,7 @@ void RemovePage(Page page) if (_container == null || page == null) return; - if (_modalBackgroundPage != null) - _modalBackgroundPage.GetCurrentPage()?.SendAppearing(); + _modalBackgroundPage?.GetCurrentPage()?.SendAppearing(); IVisualElementRenderer pageRenderer = GetRenderer(page); @@ -449,8 +448,7 @@ void AddPage(Page page) if (_container == null || page == null) return; - if (_modalBackgroundPage != null) - _modalBackgroundPage.GetCurrentPage()?.SendDisappearing(); + _modalBackgroundPage?.GetCurrentPage()?.SendDisappearing(); diff --git a/src/Compatibility/Core/src/Windows/ScrollViewRenderer.cs b/src/Compatibility/Core/src/Windows/ScrollViewRenderer.cs index cc5467fecb83..ba50c2d2a568 100644 --- a/src/Compatibility/Core/src/Windows/ScrollViewRenderer.cs +++ b/src/Compatibility/Core/src/Windows/ScrollViewRenderer.cs @@ -76,8 +76,7 @@ void CleanUp(ScrollView scrollView, ScrollViewer scrollViewer) } } - if (_currentView != null) - _currentView.Cleanup(); + _currentView?.Cleanup(); } protected override void OnElementChanged(ElementChangedEventArgs e) @@ -130,8 +129,7 @@ protected void OnContentElementPropertyChanged(object sender, PropertyChangedEve void UpdateContent() { - if (_currentView != null) - _currentView.Cleanup(); + _currentView?.Cleanup(); if (Control?.Content is FrameworkElement oldElement) { @@ -148,7 +146,7 @@ void UpdateContent() if (_currentView != null) renderer = _currentView.GetOrCreateRenderer(); - Control.Content = renderer != null ? renderer.ContainerElement : null; + Control.Content = renderer?.ContainerElement; UpdateContentMargins(); if (renderer?.Element != null) diff --git a/src/Compatibility/Core/src/Windows/Shapes/ShapeRenderer.cs b/src/Compatibility/Core/src/Windows/Shapes/ShapeRenderer.cs index bad9728ab934..cde7117b009b 100644 --- a/src/Compatibility/Core/src/Windows/Shapes/ShapeRenderer.cs +++ b/src/Compatibility/Core/src/Windows/Shapes/ShapeRenderer.cs @@ -144,8 +144,7 @@ void UpdateStrokeThickness() void UpdateStrokeDashArray() { - if (Control.StrokeDashArray != null) - Control.StrokeDashArray.Clear(); + Control.StrokeDashArray?.Clear(); if (Element.StrokeDashArray != null && Element.StrokeDashArray.Count > 0) { diff --git a/src/Compatibility/Core/src/Windows/TabbedPageRenderer.cs b/src/Compatibility/Core/src/Windows/TabbedPageRenderer.cs index 9deacf7ea951..de9975c58c54 100644 --- a/src/Compatibility/Core/src/Windows/TabbedPageRenderer.cs +++ b/src/Compatibility/Core/src/Windows/TabbedPageRenderer.cs @@ -63,8 +63,7 @@ protected VisualElementTracker Tracker if (_tracker == value) return; - if (_tracker != null) - _tracker.Dispose(); + _tracker?.Dispose(); _tracker = value; } diff --git a/src/Compatibility/Core/src/Windows/VisualElementRenderer.cs b/src/Compatibility/Core/src/Windows/VisualElementRenderer.cs index 3a4d32c04afb..9df6e3a40eef 100644 --- a/src/Compatibility/Core/src/Windows/VisualElementRenderer.cs +++ b/src/Compatibility/Core/src/Windows/VisualElementRenderer.cs @@ -156,8 +156,7 @@ public void SetElement(VisualElement element) // and may cause issues //Loaded += (sender, args) => //{ - if (Packager != null) - Packager.Load(); + Packager?.Load(); //}; } @@ -201,10 +200,7 @@ event EventHandler IVisualNativeElementRenderer.ControlChanged var myRect = new WRect(0, 0, finalSize.Width, finalSize.Height); - if (Control != null) - { - Control.Arrange(myRect); - } + Control?.Arrange(myRect); List arrangedChildren = null; for (var i = 0; i < ElementController.LogicalChildren.Count; i++) diff --git a/src/Compatibility/Core/src/Windows/WebViewRenderer.cs b/src/Compatibility/Core/src/Windows/WebViewRenderer.cs index 8c2b3e75971a..48e1bb8e72c3 100644 --- a/src/Compatibility/Core/src/Windows/WebViewRenderer.cs +++ b/src/Compatibility/Core/src/Windows/WebViewRenderer.cs @@ -360,8 +360,7 @@ void SyncNativeCookies(string url) void Load() { - if (Element.Source != null) - Element.Source.Load(this); + Element.Source?.Load(this); UpdateCanGoBackForward(); } diff --git a/src/Compatibility/Core/src/iOS/Cells/CellTableViewCell.cs b/src/Compatibility/Core/src/iOS/Cells/CellTableViewCell.cs index e644d5dc1c0b..1d6cc3cff84d 100644 --- a/src/Compatibility/Core/src/iOS/Cells/CellTableViewCell.cs +++ b/src/Compatibility/Core/src/iOS/Cells/CellTableViewCell.cs @@ -92,8 +92,7 @@ internal static UITableViewCell GetNativeCell(UITableView tableView, Cell cell, } // Because the layer was hidden we need to layout the cell by hand - if (cellWithContent != null) - cellWithContent.LayoutSubviews(); + cellWithContent?.LayoutSubviews(); return nativeCell; } diff --git a/src/Compatibility/Core/src/iOS/CollectionView/ItemsViewRenderer.cs b/src/Compatibility/Core/src/iOS/CollectionView/ItemsViewRenderer.cs index c6d43b4c3179..af510aeafe36 100644 --- a/src/Compatibility/Core/src/iOS/CollectionView/ItemsViewRenderer.cs +++ b/src/Compatibility/Core/src/iOS/CollectionView/ItemsViewRenderer.cs @@ -118,10 +118,7 @@ protected virtual void UpdateLayout() { _layout = SelectLayout(); - if (Controller != null) - { - Controller.UpdateLayout(_layout); - } + Controller?.UpdateLayout(_layout); } protected virtual void UpdateItemSizingStrategy() diff --git a/src/Compatibility/Core/src/iOS/CollectionView/StructuredItemsViewController.cs b/src/Compatibility/Core/src/iOS/CollectionView/StructuredItemsViewController.cs index c0362cb6e46d..e53f629a690c 100644 --- a/src/Compatibility/Core/src/iOS/CollectionView/StructuredItemsViewController.cs +++ b/src/Compatibility/Core/src/iOS/CollectionView/StructuredItemsViewController.cs @@ -140,9 +140,9 @@ internal void UpdateSubview(object view, DataTemplate viewTemplate, nint viewTag RemeasureLayout(formsElement); formsElement.MeasureInvalidated += OnFormsElementMeasureInvalidated; } - else if (uiView != null) + else { - uiView.SizeToFit(); + uiView?.SizeToFit(); } } diff --git a/src/Compatibility/Core/src/iOS/Renderers/ActivityIndicatorRenderer.cs b/src/Compatibility/Core/src/iOS/Renderers/ActivityIndicatorRenderer.cs index e2aa9c73045b..b31b43262c26 100644 --- a/src/Compatibility/Core/src/iOS/Renderers/ActivityIndicatorRenderer.cs +++ b/src/Compatibility/Core/src/iOS/Renderers/ActivityIndicatorRenderer.cs @@ -77,7 +77,7 @@ protected override void OnElementPropertyChanged(object sender, PropertyChangedE [PortHandler] void UpdateColor() { - Control.Color = Element.Color == null ? null : Element.Color.ToPlatform(); + Control.Color = Element.Color?.ToPlatform(); } [PortHandler] diff --git a/src/Compatibility/Core/src/iOS/Renderers/ButtonRenderer.cs b/src/Compatibility/Core/src/iOS/Renderers/ButtonRenderer.cs index eda73f82a2e4..a0b65bb65a0d 100644 --- a/src/Compatibility/Core/src/iOS/Renderers/ButtonRenderer.cs +++ b/src/Compatibility/Core/src/iOS/Renderers/ButtonRenderer.cs @@ -164,7 +164,7 @@ protected override void SetBackground(Brush brush) if (Control == null) return; - UIColor backgroundColor = Element.BackgroundColor == null ? null : Element.BackgroundColor.ToPlatform(); + UIColor backgroundColor = Element.BackgroundColor?.ToPlatform(); if (!Brush.IsNullOrEmpty(brush)) { diff --git a/src/Compatibility/Core/src/iOS/Renderers/CarouselPageRenderer.cs b/src/Compatibility/Core/src/iOS/Renderers/CarouselPageRenderer.cs index 6d3514a6aa8a..3bcd9277a215 100644 --- a/src/Compatibility/Core/src/iOS/Renderers/CarouselPageRenderer.cs +++ b/src/Compatibility/Core/src/iOS/Renderers/CarouselPageRenderer.cs @@ -68,8 +68,7 @@ public void SetElement(VisualElement element) OnElementChanged(new VisualElementChangedEventArgs(oldElement, element)); - if (element != null) - element.SendViewInitialized(NativeView); + element?.SendViewInitialized(NativeView); _previousPage = Carousel?.CurrentPage; } diff --git a/src/Compatibility/Core/src/iOS/Renderers/ListViewRenderer.cs b/src/Compatibility/Core/src/iOS/Renderers/ListViewRenderer.cs index 38b1eda611b1..44375409000c 100644 --- a/src/Compatibility/Core/src/iOS/Renderers/ListViewRenderer.cs +++ b/src/Compatibility/Core/src/iOS/Renderers/ListViewRenderer.cs @@ -561,8 +561,7 @@ void UpdateHeader() void UpdateIsRefreshing() { var refreshing = Element.IsRefreshing; - if (_tableViewController != null) - _tableViewController.UpdateIsRefreshing(refreshing); + _tableViewController?.UpdateIsRefreshing(refreshing); } void UpdateItems(NotifyCollectionChangedEventArgs e, int section, bool resetWhenGrouped) @@ -779,8 +778,7 @@ void UpdateSpinnerColor() { var color = Element.RefreshControlColor; - if (_tableViewController != null) - _tableViewController.UpdateRefreshControlColor(color?.ToPlatform()); + _tableViewController?.UpdateRefreshControlColor(color?.ToPlatform()); } void UpdateVerticalScrollBarVisibility() diff --git a/src/Compatibility/Core/src/iOS/Renderers/NavigationRenderer.cs b/src/Compatibility/Core/src/iOS/Renderers/NavigationRenderer.cs index 6b85dadcdd82..07295549a43a 100644 --- a/src/Compatibility/Core/src/iOS/Renderers/NavigationRenderer.cs +++ b/src/Compatibility/Core/src/iOS/Renderers/NavigationRenderer.cs @@ -78,8 +78,7 @@ public void SetElement(VisualElement element) Element = element; OnElementChanged(new VisualElementChangedEventArgs(oldElement, element)); - if (element != null) - element.SendViewInitialized(NativeView); + element?.SendViewInitialized(NativeView); EffectUtilities.RegisterEffectControlProvider(this, oldElement, element); } @@ -271,8 +270,7 @@ protected override void Dispose(bool disposing) foreach (var childViewController in ViewControllers) childViewController.Dispose(); - if (_tracker != null) - _tracker.Dispose(); + _tracker?.Dispose(); _secondaryToolbar.RemoveFromSuperview(); _secondaryToolbar.Dispose(); @@ -1420,8 +1418,7 @@ void UpdateToolbarItems() (primaries = primaries ?? new List()).Add(item.ToUIBarButtonItem()); } - if (primaries != null) - primaries.Reverse(); + primaries?.Reverse(); NavigationItem.SetRightBarButtonItems(primaries == null ? Array.Empty() : primaries.ToArray(), false); ToolbarItems = secondaries == null ? Array.Empty() : secondaries.ToArray(); @@ -1656,8 +1653,7 @@ public UIImageView Icon { set { - if (_icon != null) - _icon.RemoveFromSuperview(); + _icon?.RemoveFromSuperview(); _icon = value; diff --git a/src/Compatibility/Core/src/iOS/Renderers/PhoneFlyoutPageRenderer.cs b/src/Compatibility/Core/src/iOS/Renderers/PhoneFlyoutPageRenderer.cs index 437a6d82c93d..fadd2d27c6bc 100644 --- a/src/Compatibility/Core/src/iOS/Renderers/PhoneFlyoutPageRenderer.cs +++ b/src/Compatibility/Core/src/iOS/Renderers/PhoneFlyoutPageRenderer.cs @@ -94,8 +94,7 @@ public void SetElement(VisualElement element) EffectUtilities.RegisterEffectControlProvider(this, oldElement, element); - if (element != null) - element.SendViewInitialized(NativeView); + element?.SendViewInitialized(NativeView); } public void SetElementSize(Size size) diff --git a/src/Compatibility/Core/src/iOS/Renderers/ProgressBarRenderer.cs b/src/Compatibility/Core/src/iOS/Renderers/ProgressBarRenderer.cs index 10e8818dd905..26fe8a66db27 100644 --- a/src/Compatibility/Core/src/iOS/Renderers/ProgressBarRenderer.cs +++ b/src/Compatibility/Core/src/iOS/Renderers/ProgressBarRenderer.cs @@ -56,13 +56,13 @@ protected override void SetBackgroundColor(Color color) if (Control == null) return; - Control.TrackTintColor = color != null ? color.ToPlatform() : null; + Control.TrackTintColor = color?.ToPlatform(); } [PortHandler] void UpdateProgressColor() { - Control.ProgressTintColor = Element.ProgressColor == null ? null : Element.ProgressColor.ToPlatform(); + Control.ProgressTintColor = Element.ProgressColor?.ToPlatform(); } [PortHandler] diff --git a/src/Compatibility/Core/src/iOS/Renderers/ScrollViewRenderer.cs b/src/Compatibility/Core/src/iOS/Renderers/ScrollViewRenderer.cs index 79542e8d2cb4..b214b940d3f4 100644 --- a/src/Compatibility/Core/src/iOS/Renderers/ScrollViewRenderer.cs +++ b/src/Compatibility/Core/src/iOS/Renderers/ScrollViewRenderer.cs @@ -108,8 +108,7 @@ public void SetElement(VisualElement element) EffectUtilities.RegisterEffectControlProvider(this, oldElement, element); - if (element != null) - element.SendViewInitialized(this); + element?.SendViewInitialized(this); if (!string.IsNullOrEmpty(element.AutomationId)) AccessibilityIdentifier = element.AutomationId; @@ -336,8 +335,7 @@ CoreGraphics.CGSize RetrieveElementContentSize() void UpdateScrollPosition() { - if (ScrollView != null) - ScrollView.SetScrolledPosition(ContentOffset.X, ContentOffset.Y); + ScrollView?.SetScrolledPosition(ContentOffset.X, ContentOffset.Y); } void IEffectControlProvider.RegisterEffect(Effect effect) diff --git a/src/Compatibility/Core/src/iOS/Renderers/SwipeViewRenderer.cs b/src/Compatibility/Core/src/iOS/Renderers/SwipeViewRenderer.cs index e268af3166de..1f71d941b175 100644 --- a/src/Compatibility/Core/src/iOS/Renderers/SwipeViewRenderer.cs +++ b/src/Compatibility/Core/src/iOS/Renderers/SwipeViewRenderer.cs @@ -178,8 +178,7 @@ protected override void SetBackground(Brush brush) if (Brush.IsNullOrEmpty(background)) return; - if (Control != null) - Control.UpdateBackground(background); + Control?.UpdateBackground(background); } public override void TouchesEnded(NSSet touches, UIEvent evt) diff --git a/src/Compatibility/Core/src/iOS/Renderers/TabbedRenderer.cs b/src/Compatibility/Core/src/iOS/Renderers/TabbedRenderer.cs index c00e027ef77b..4d37ef791fd8 100644 --- a/src/Compatibility/Core/src/iOS/Renderers/TabbedRenderer.cs +++ b/src/Compatibility/Core/src/iOS/Renderers/TabbedRenderer.cs @@ -78,8 +78,7 @@ public void SetElement(VisualElement element) OnPagesChanged(null, new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); - if (element != null) - element.SendViewInitialized(NativeView); + element?.SendViewInitialized(NativeView); //disable edit/reorder of tabs CustomizableViewControllers = null; diff --git a/src/Compatibility/Core/src/iOS/Renderers/TableViewModelRenderer.cs b/src/Compatibility/Core/src/iOS/Renderers/TableViewModelRenderer.cs index fc8eb74631e2..8e86b9ec2b60 100644 --- a/src/Compatibility/Core/src/iOS/Renderers/TableViewModelRenderer.cs +++ b/src/Compatibility/Core/src/iOS/Renderers/TableViewModelRenderer.cs @@ -21,8 +21,7 @@ public TableViewModelRenderer(TableView model) View = model; View.ModelChanged += (s, e) => { - if (Table != null) - Table.ReloadData(); + Table?.ReloadData(); }; AutomaticallyDeselect = true; } diff --git a/src/Compatibility/Core/src/iOS/Renderers/TabletFlyoutPageRenderer.cs b/src/Compatibility/Core/src/iOS/Renderers/TabletFlyoutPageRenderer.cs index 9c89e8f3171d..0451da69cbb5 100644 --- a/src/Compatibility/Core/src/iOS/Renderers/TabletFlyoutPageRenderer.cs +++ b/src/Compatibility/Core/src/iOS/Renderers/TabletFlyoutPageRenderer.cs @@ -223,8 +223,7 @@ public void SetElement(VisualElement element) EffectUtilities.RegisterEffectControlProvider(this, oldElement, element); - if (element != null) - element.SendViewInitialized(NativeView); + element?.SendViewInitialized(NativeView); } public void SetElementSize(Size size) diff --git a/src/Compatibility/Core/src/iOS/Renderers/UIContainerCell.cs b/src/Compatibility/Core/src/iOS/Renderers/UIContainerCell.cs index d50b60a90202..d8dd7c43dff6 100644 --- a/src/Compatibility/Core/src/iOS/Renderers/UIContainerCell.cs +++ b/src/Compatibility/Core/src/iOS/Renderers/UIContainerCell.cs @@ -34,8 +34,7 @@ internal UIContainerCell(string cellId, View view, Shell shell, object context) ContentView.ClipsToBounds = true; BindingContext = context; - if (shell != null) - shell.AddLogicalChild(View); + shell?.AddLogicalChild(View); } @@ -68,8 +67,7 @@ internal void Disconnect(Shell shell = null, bool keepRenderer = false) if (!keepRenderer) Platform.SetRenderer(View, null); - if (shell != null) - shell.RemoveLogicalChild(shell); + shell?.RemoveLogicalChild(shell); View = null; TableView = null; @@ -102,8 +100,7 @@ public object BindingContext public override void LayoutSubviews() { base.LayoutSubviews(); - if (View != null) - View.Layout(Bounds.ToRectangle()); + View?.Layout(Bounds.ToRectangle()); } void UpdateVisualState() diff --git a/src/Compatibility/Core/src/iOS/Renderers/WkWebViewRenderer.cs b/src/Compatibility/Core/src/iOS/Renderers/WkWebViewRenderer.cs index a9b50caa341b..dcb88d0e2866 100644 --- a/src/Compatibility/Core/src/iOS/Renderers/WkWebViewRenderer.cs +++ b/src/Compatibility/Core/src/iOS/Renderers/WkWebViewRenderer.cs @@ -126,8 +126,7 @@ public void SetElement(VisualElement element) if (Element != null && !string.IsNullOrEmpty(Element.AutomationId)) AccessibilityIdentifier = Element.AutomationId; - if (element != null) - element.SendViewInitialized(this); + element?.SendViewInitialized(this); } public void SetElementSize(Size size) @@ -589,8 +588,7 @@ void Load() if (_ignoreSourceChanges) return; - if (((WebView)Element).Source != null) - ((WebView)Element).Source.Load(this); + ((WebView)Element).Source?.Load(this); UpdateCanGoBackForward(); } diff --git a/src/Controls/Foldable/src/Android/FoldableService.cs b/src/Controls/Foldable/src/Android/FoldableService.cs index 40a750210576..e7250ea447d3 100644 --- a/src/Controls/Foldable/src/Android/FoldableService.cs +++ b/src/Controls/Foldable/src/Android/FoldableService.cs @@ -401,8 +401,7 @@ void SetHingeAngle(int hingeAngle) _gettingHingeAngle = null; } - if (toSet != null) - toSet.SetResult(hingeAngle); + toSet?.SetResult(hingeAngle); } } diff --git a/src/Controls/src/Core/Binding.cs b/src/Controls/src/Core/Binding.cs index be91c9f8c178..74ca4eeaa267 100644 --- a/src/Controls/src/Core/Binding.cs +++ b/src/Controls/src/Core/Binding.cs @@ -200,10 +200,7 @@ internal override void Unapply(bool fromBindingContextChanged = false) base.Unapply(fromBindingContextChanged: fromBindingContextChanged); - if (_expression != null) - { - _expression.Unapply(); - } + _expression?.Unapply(); } } } \ No newline at end of file diff --git a/src/Controls/src/Core/CollectionSynchronizationContext.cs b/src/Controls/src/Core/CollectionSynchronizationContext.cs index 5d3de023de03..95203b11fa4d 100644 --- a/src/Controls/src/Core/CollectionSynchronizationContext.cs +++ b/src/Controls/src/Core/CollectionSynchronizationContext.cs @@ -15,7 +15,7 @@ internal CollectionSynchronizationContext(object context, CollectionSynchronizat internal object Context { - get { return ContextReference != null ? ContextReference.Target : null; } + get { return ContextReference?.Target; } } internal WeakReference ContextReference { get; } diff --git a/src/Controls/src/Core/Compatibility/Handlers/Android/VisualElementRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/Android/VisualElementRenderer.cs index 88c05a9a3649..5d61dcb51b0d 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Android/VisualElementRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Android/VisualElementRenderer.cs @@ -48,10 +48,7 @@ protected override void OnLayout(bool changed, int l, int t, int r, int b) if (ChildCount > 0) { var platformView = GetChildAt(0); - if (platformView != null) - { - platformView.Layout(0, 0, r - l, b - t); - } + platformView?.Layout(0, 0, r - l, b - t); } } diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/EntryCellView.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/EntryCellView.cs index 621db975cbe1..9a42e2b6c043 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/EntryCellView.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/Android/EntryCellView.cs @@ -118,7 +118,7 @@ void ITextWatcher.OnTextChanged(ICharSequence s, int start, int before, int coun { Action changed = TextChanged; if (changed != null) - changed(s != null ? s.ToString() : null); + changed(s?.ToString()); } public void SetLabelTextColor(Color color, int defaultColorResourceId) diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/Windows/CellControl.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/Windows/CellControl.cs index 6e9c5b0b94bc..459a51c70c60 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/Windows/CellControl.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/Windows/CellControl.cs @@ -130,10 +130,7 @@ protected FrameworkElement CellContent // Children still need measure called on them global::Windows.Foundation.Size result = base.MeasureOverride(availableSize); - if (lv != null) - { - lv.SetValue(MeasuredEstimateProperty, result.Height); - } + lv?.SetValue(MeasuredEstimateProperty, result.Height); SetDefaultSwitchColor(); diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/Windows/ListGroupHeaderPresenter.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/Windows/ListGroupHeaderPresenter.cs index ee83a0a5977a..15b556b8dd8a 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/Windows/ListGroupHeaderPresenter.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/Windows/ListGroupHeaderPresenter.cs @@ -26,10 +26,7 @@ void OnTapped(object sender, TappedRoutedEventArgs tappedRoutedEventArgs) zoom.ToggleActiveView(); var grid = zoom.ZoomedOutView as GridView; - if (grid != null) - { - grid.MakeVisible(new SemanticZoomLocation { Item = DataContext }); - } + grid?.MakeVisible(new SemanticZoomLocation { Item = DataContext }); return; } diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/CellTableViewCell.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/CellTableViewCell.cs index 84ad28b6f1dd..950ee0bdb347 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/CellTableViewCell.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/CellTableViewCell.cs @@ -101,8 +101,7 @@ internal static UITableViewCell GetPlatformCell(UITableView tableView, Cell cell } // Because the layer was hidden we need to layout the cell by hand - if (cellWithContent != null) - cellWithContent.LayoutSubviews(); + cellWithContent?.LayoutSubviews(); return platformCell; } diff --git a/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ListViewRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ListViewRenderer.cs index d8e3d04c2c31..9dcf018f502f 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ListViewRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/ListView/iOS/ListViewRenderer.cs @@ -446,8 +446,7 @@ void OnScrollToRequested(object sender, ScrollToRequestedEventArgs e) if (OperatingSystem.IsIOSVersionAtLeast(11) || OperatingSystem.IsTvOSVersionAtLeast(11)) this.BeginInvokeOnMainThread(() => { - if (Control != null /*&& !_disposed*/) - Control.ScrollToRow(NSIndexPath.FromRowSection(index, 0), position, e.ShouldAnimate); + Control?.ScrollToRow(NSIndexPath.FromRowSection(index, 0), position, e.ShouldAnimate); }); else Control.ScrollToRow(NSIndexPath.FromRowSection(index, 0), position, e.ShouldAnimate); @@ -535,8 +534,7 @@ void UpdateHeader() void UpdateIsRefreshing() { var refreshing = Element.IsRefreshing; - if (_tableViewController != null) - _tableViewController.UpdateIsRefreshing(refreshing); + _tableViewController?.UpdateIsRefreshing(refreshing); } void UpdateItems(NotifyCollectionChangedEventArgs e, int section, bool resetWhenGrouped) @@ -756,8 +754,7 @@ void UpdateSpinnerColor() { var color = Element.RefreshControlColor; - if (_tableViewController != null) - _tableViewController.UpdateRefreshControlColor(color?.ToPlatform()); + _tableViewController?.UpdateRefreshControlColor(color?.ToPlatform()); } void UpdateVerticalScrollBarVisibility() diff --git a/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs index 54366c0e1c15..b84444975463 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/NavigationPage/iOS/NavigationRenderer.cs @@ -1692,8 +1692,7 @@ void UpdateToolbarItems() (primaries = primaries ?? new List()).Add(item.ToUIBarButtonItem()); } - if (primaries != null) - primaries.Reverse(); + primaries?.Reverse(); NavigationItem.SetRightBarButtonItems(primaries == null ? Array.Empty() : primaries.ToArray(), false); ToolbarItems = secondaries == null ? Array.Empty() : secondaries.ToArray(); @@ -2010,8 +2009,7 @@ public UIImageView Icon { set { - if (_icon != null) - _icon.RemoveFromSuperview(); + _icon?.RemoveFromSuperview(); _icon = value; diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellSectionRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellSectionRenderer.cs index 24ceab4a95cf..c04fb0afa922 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellSectionRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/Android/ShellSectionRenderer.cs @@ -166,10 +166,7 @@ void UpdateTabTitle(ShellContent shellContent) if (index >= 0) { var tab = _tablayout.GetTabAt(index); - if (tab != null) - { - tab.SetText(new string(shellContent.Title)); - } + tab?.SetText(new string(shellContent.Title)); } } diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/SearchHandlerAppearanceTracker.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/SearchHandlerAppearanceTracker.cs index c155925e8bea..2a7769dac9c8 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/SearchHandlerAppearanceTracker.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/SearchHandlerAppearanceTracker.cs @@ -114,7 +114,7 @@ void SearchHandlerPropertyChanged(object sender, System.ComponentModel.PropertyC else if (e.Is(SearchHandler.VerticalTextAlignmentProperty)) { UpdateSearchBarVerticalTextAlignment(_uiSearchBar.FindDescendantView()); - } + } } void GetDefaultSearchBarColors(UISearchBar searchBar) diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellFlyoutRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellFlyoutRenderer.cs index f20d145832eb..4ddb69f39500 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellFlyoutRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellFlyoutRenderer.cs @@ -450,10 +450,7 @@ void LayoutSidebar(bool animate, bool cancelExisting = false) { FlyoutTransition.LayoutViews(View.Bounds, IsOpen ? 1 : 0, Flyout.ViewController.View, Detail.View, _flyoutBehavior); - if (TapoffView != null) - { - TapoffView.Layer.AddAnimation(tapOffViewAnimation, "opacity"); - } + TapoffView?.Layer.AddAnimation(tapOffViewAnimation, "opacity"); }); _flyoutAnimation.AddCompletion((p) => 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 20a796ef98d4..a946bd1f741c 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellPageRendererTracker.cs @@ -316,8 +316,7 @@ protected virtual void UpdateToolbarItems() } } - if (primaries != null) - primaries.Reverse(); + primaries?.Reverse(); NavigationItem.SetRightBarButtonItems(primaries == null ? Array.Empty() : primaries.ToArray(), false); @@ -698,10 +697,7 @@ protected virtual void UpdateSearchVisibility(UISearchController searchControlle void UpdateFlowDirection() { - if (_searchHandlerAppearanceTracker != null) - { - _searchHandlerAppearanceTracker.UpdateFlowDirection(_context.Shell); - } + _searchHandlerAppearanceTracker?.UpdateFlowDirection(_context.Shell); if (_searchController != null) { _searchController.View.UpdateFlowDirection(_context.Shell); diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRenderer.cs index 2f2d90e48f85..a80034b289b8 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/ShellSectionRenderer.cs @@ -774,9 +774,9 @@ public override void DidShowViewController(UINavigationController navigationCont source.TrySetResult(true); tasks.Remove(viewController); } - else if (popTask != null) + else { - popTask.TrySetResult(true); + popTask?.TrySetResult(true); } } diff --git a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/UIContainerCell.cs b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/UIContainerCell.cs index 51a6c3707f6f..b93e55b34e83 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/UIContainerCell.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/Shell/iOS/UIContainerCell.cs @@ -50,8 +50,8 @@ internal UIContainerCell(string cellId, View view, Shell shell, object context) if (BindingContext is BaseShellItem bsi) bsi.AddLogicalChild(View); - else if (shell != null) - shell.AddLogicalChild(View); + else + shell?.AddLogicalChild(View); } public UIContainerCell(string cellId, View view) : this(cellId, view, null, null) @@ -80,8 +80,8 @@ internal void Disconnect(Shell shell = null, bool keepRenderer = false) if (View.Parent is BaseShellItem bsi) bsi.RemoveLogicalChild(View); - else if (shell != null) - shell.RemoveLogicalChild(View); + else + shell?.RemoveLogicalChild(View); _bindingContext = null; diff --git a/src/Controls/src/Core/Compatibility/Handlers/TableView/iOS/TableViewRenderer.cs b/src/Controls/src/Core/Compatibility/Handlers/TableView/iOS/TableViewRenderer.cs index b859af8cd439..a9185090054c 100644 --- a/src/Controls/src/Core/Compatibility/Handlers/TableView/iOS/TableViewRenderer.cs +++ b/src/Controls/src/Core/Compatibility/Handlers/TableView/iOS/TableViewRenderer.cs @@ -73,8 +73,7 @@ protected override void OnElementChanged(ElementChangedEventArgs e) if (Control == null || Control.Style != style) { - if (Control != null) - Control.Dispose(); + Control?.Dispose(); var tv = CreateNativeControl(); _originalBackgroundView = tv.BackgroundView; diff --git a/src/Controls/src/Core/Handlers/Items/Android/MauiCarouselRecyclerView.cs b/src/Controls/src/Core/Handlers/Items/Android/MauiCarouselRecyclerView.cs index 0838765d1d26..8e0a4f63272d 100644 --- a/src/Controls/src/Core/Handlers/Items/Android/MauiCarouselRecyclerView.cs +++ b/src/Controls/src/Core/Handlers/Items/Android/MauiCarouselRecyclerView.cs @@ -169,10 +169,7 @@ protected override void UpdateItemSpacing() var adapter = GetAdapter(); - if (adapter != null) - { - adapter.NotifyItemChanged(_oldPosition); - } + adapter?.NotifyItemChanged(_oldPosition); base.UpdateItemSpacing(); } diff --git a/src/Controls/src/Core/Handlers/Items/iOS/ReorderableItemsViewController.cs b/src/Controls/src/Core/Handlers/Items/iOS/ReorderableItemsViewController.cs index d70b9c92c8d9..ad1e022f0c69 100644 --- a/src/Controls/src/Core/Handlers/Items/iOS/ReorderableItemsViewController.cs +++ b/src/Controls/src/Core/Handlers/Items/iOS/ReorderableItemsViewController.cs @@ -44,14 +44,11 @@ protected override UICollectionViewDelegateFlowLayout CreateDelegator() protected override IItemsViewSource CreateItemsViewSource() { - if (ItemsSource != null) - { - // There's a bug in the current Maui Controls library. - // It will call "CreateItemsViewSource" 2x in a row when opening a page. - // It's invoked from both ViewDidLoad & UpdateItemsSource - // For the time being, until the issue is fixed, we need to dispose of the current source if one already exist. - ItemsSource.Dispose(); - } + // There's a bug in the current Maui Controls library. + // It will call "CreateItemsViewSource" 2x in a row when opening a page. + // It's invoked from both ViewDidLoad & UpdateItemsSource + // For the time being, until the issue is fixed, we need to dispose of the current source if one already exist. + ItemsSource?.Dispose(); return base.CreateItemsViewSource(); } diff --git a/src/Controls/src/Core/Handlers/Items2/iOS/ReorderableItemsViewController2.cs b/src/Controls/src/Core/Handlers/Items2/iOS/ReorderableItemsViewController2.cs index 2cf389c6a485..616987b09192 100644 --- a/src/Controls/src/Core/Handlers/Items2/iOS/ReorderableItemsViewController2.cs +++ b/src/Controls/src/Core/Handlers/Items2/iOS/ReorderableItemsViewController2.cs @@ -44,14 +44,11 @@ protected override UICollectionViewDelegateFlowLayout CreateDelegator() protected override Items.IItemsViewSource CreateItemsViewSource() { - if (ItemsSource != null) - { - // There's a bug in the current Maui Controls library. - // It will call "CreateItemsViewSource" 2x in a row when opening a page. - // It's invoked from both ViewDidLoad & UpdateItemsSource - // For the time being, until the issue is fixed, we need to dispose of the current source if one already exist. - ItemsSource.Dispose(); - } + // There's a bug in the current Maui Controls library. + // It will call "CreateItemsViewSource" 2x in a row when opening a page. + // It's invoked from both ViewDidLoad & UpdateItemsSource + // For the time being, until the issue is fixed, we need to dispose of the current source if one already exist. + ItemsSource?.Dispose(); return base.CreateItemsViewSource(); } diff --git a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellView.cs b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellView.cs index 726e2c5ee81f..5220a30c0e1d 100644 --- a/src/Controls/src/Core/Handlers/Shell/Tizen/ShellView.cs +++ b/src/Controls/src/Core/Handlers/Shell/Tizen/ShellView.cs @@ -145,8 +145,7 @@ public void UpdateBackgroundColor(GColor color) public void UpdateCurrentItem(ShellItem newItem) { - if (_currentItemHandler != null) - _currentItemHandler.Dispose(); + _currentItemHandler?.Dispose(); if (newItem != null) { diff --git a/src/Controls/src/Core/ImageSource.cs b/src/Controls/src/Core/ImageSource.cs index d85f99ba78cb..836ed4871689 100644 --- a/src/Controls/src/Core/ImageSource.cs +++ b/src/Controls/src/Core/ImageSource.cs @@ -38,8 +38,7 @@ private set { if (_cancellationTokenSource == value) return; - if (_cancellationTokenSource != null) - _cancellationTokenSource.Cancel(); + _cancellationTokenSource?.Cancel(); _cancellationTokenSource = value; } } @@ -127,8 +126,7 @@ private protected async Task OnLoadingCompleted(bool cancelled) return; TaskCompletionSource tcs = Interlocked.Exchange(ref _completionSource, null); - if (tcs != null) - tcs.SetResult(cancelled); + tcs?.SetResult(cancelled); await _cancellationTokenSourceLock.WaitAsync(); try diff --git a/src/Controls/src/Core/Label/Label.Mapper.cs b/src/Controls/src/Core/Label/Label.Mapper.cs index 50836bb7a6fd..e388dd47272b 100644 --- a/src/Controls/src/Core/Label/Label.Mapper.cs +++ b/src/Controls/src/Core/Label/Label.Mapper.cs @@ -56,14 +56,16 @@ static void MapTextTransform(ILabelHandler handler, Label label) => MapTextOrFormattedText(handler, label); static void MapFormattedText(ILabelHandler handler, Label label) { - if (label.IsConnectingHandler()) return; + if (label.IsConnectingHandler()) + return; MapText(handler, label); } static void MapTextOrFormattedText(ILabelHandler handler, Label label) { - if (label.IsConnectingHandler()) return; + if (label.IsConnectingHandler()) + return; if (label.HasFormattedTextSpans) handler.UpdateValue(nameof(FormattedText)); diff --git a/src/Controls/src/Core/ListProxy.cs b/src/Controls/src/Core/ListProxy.cs index eb217a0d96dc..82a9eaf1e08b 100644 --- a/src/Controls/src/Core/ListProxy.cs +++ b/src/Controls/src/Core/ListProxy.cs @@ -147,16 +147,13 @@ public void Clear() if (_enumerator != null) { var dispose = _enumerator as IDisposable; - if (dispose != null) - dispose.Dispose(); + dispose?.Dispose(); _enumerator = null; } - if (_items != null) - _items.Clear(); - if (_indexesCounted != null) - _indexesCounted.Clear(); + _items?.Clear(); + _indexesCounted?.Clear(); OnCountChanged(); OnCollectionChanged(new NotifyCollectionChangedEventArgs(NotifyCollectionChangedAction.Reset)); @@ -303,8 +300,7 @@ bool TryGetValue(int index, out object value) _windowIndex = 0; var dispose = _enumerator as IDisposable; - if (dispose != null) - dispose.Dispose(); + dispose?.Dispose(); _enumerator = null; _enumeratorIndex = 0; @@ -335,8 +331,7 @@ bool TryGetValue(int index, out object value) if (!moved) { var dispose = _enumerator as IDisposable; - if (dispose != null) - dispose.Dispose(); + dispose?.Dispose(); _enumerator = null; _enumeratorIndex = 0; diff --git a/src/Controls/src/Core/LockingSemaphore.cs b/src/Controls/src/Core/LockingSemaphore.cs index cb6edde1d24e..31c239b17196 100644 --- a/src/Controls/src/Core/LockingSemaphore.cs +++ b/src/Controls/src/Core/LockingSemaphore.cs @@ -29,8 +29,7 @@ public void Release() else ++_currentCount; } - if (toRelease != null) - toRelease.TrySetResult(true); + toRelease?.TrySetResult(true); } public Task WaitAsync(CancellationToken token) diff --git a/src/Controls/src/Core/Platform/Android/Extensions/ToolbarExtensions.cs b/src/Controls/src/Core/Platform/Android/Extensions/ToolbarExtensions.cs index 7f45b0412371..eb8e5dd7a673 100644 --- a/src/Controls/src/Core/Platform/Android/Extensions/ToolbarExtensions.cs +++ b/src/Controls/src/Core/Platform/Android/Extensions/ToolbarExtensions.cs @@ -261,10 +261,7 @@ public static void UpdateMenuItems(this AToolbar toolbar, int toolBarItemCount = i; while (toolBarItemCount < previousMenuItems.Count) { - if (menu != null) - { - menu.RemoveItem(previousMenuItems[toolBarItemCount].ItemId); - } + menu?.RemoveItem(previousMenuItems[toolBarItemCount].ItemId); previousMenuItems[toolBarItemCount].Dispose(); previousMenuItems.RemoveAt(toolBarItemCount); } diff --git a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs index f942315f1e02..76b03146df0d 100644 --- a/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs +++ b/src/Controls/src/Core/Platform/GestureManager/GesturePlatformManager.iOS.cs @@ -93,8 +93,7 @@ public void Dispose() if (uiGestureRecognizer is null) continue; - if (PlatformView != null) - PlatformView.RemoveGestureRecognizer(uiGestureRecognizer); + PlatformView?.RemoveGestureRecognizer(uiGestureRecognizer); uiGestureRecognizer.ShouldReceiveTouch = null; uiGestureRecognizer.Dispose(); } @@ -698,10 +697,7 @@ _handler.VirtualView is View v && if (uiRecognizer is null) continue; - if (PlatformView != null) - { - PlatformView.RemoveGestureRecognizer(uiRecognizer); - } + PlatformView?.RemoveGestureRecognizer(uiRecognizer); if (TryGetTapGestureRecognizer(gestureRecognizer, out TapGestureRecognizer? tapGestureRecognizer) && tapGestureRecognizer != null) diff --git a/src/Controls/src/Core/Platform/Windows/FormsListView.cs b/src/Controls/src/Core/Platform/Windows/FormsListView.cs index 8183b6fd5272..a76f696b61a0 100644 --- a/src/Controls/src/Core/Platform/Windows/FormsListView.cs +++ b/src/Controls/src/Core/Platform/Windows/FormsListView.cs @@ -80,10 +80,7 @@ protected override void OnApplyTemplate() protected override global::Windows.Foundation.Size ArrangeOverride(global::Windows.Foundation.Size finalSize) { - if (_formsEmptyView != null) - { - _formsEmptyView.Layout(new Rect(0, 0, finalSize.Width, finalSize.Height)); - } + _formsEmptyView?.Layout(new Rect(0, 0, finalSize.Width, finalSize.Height)); return base.ArrangeOverride(finalSize); } diff --git a/src/Controls/src/Core/Shapes/Path.cs b/src/Controls/src/Core/Shapes/Path.cs index 3ca2c5b34c1d..87ae0f84669a 100644 --- a/src/Controls/src/Core/Shapes/Path.cs +++ b/src/Controls/src/Core/Shapes/Path.cs @@ -109,8 +109,7 @@ public override PathF GetPath() { var path = new PathF(); - if (Data != null) - Data.AppendPath(path); + Data?.AppendPath(path); return path; } diff --git a/src/Controls/src/Core/TemplateBinding.cs b/src/Controls/src/Core/TemplateBinding.cs index 288bae4a56a6..da0820f30ebc 100644 --- a/src/Controls/src/Core/TemplateBinding.cs +++ b/src/Controls/src/Core/TemplateBinding.cs @@ -127,8 +127,7 @@ internal override void Unapply(bool fromBindingContextChanged = false) { base.Unapply(fromBindingContextChanged: fromBindingContextChanged); - if (_expression != null) - _expression.Unapply(); + _expression?.Unapply(); } void ApplyInner(Element templatedParent, BindableObject bindableObject, BindableProperty targetProperty) diff --git a/src/Controls/tests/TestCases.HostApp/CoreViews/CorePageView.cs b/src/Controls/tests/TestCases.HostApp/CoreViews/CorePageView.cs index 9a48bb47c447..99d9ae8bab68 100644 --- a/src/Controls/tests/TestCases.HostApp/CoreViews/CorePageView.cs +++ b/src/Controls/tests/TestCases.HostApp/CoreViews/CorePageView.cs @@ -140,7 +140,7 @@ public CorePageView(Page rootPage) { var realize = page.Realize(); - Dispatcher.Dispatch(() => Application.Current.MainPage = realize); + Dispatcher.Dispatch(() => Application.Current.MainPage = realize); } SelectedItem = null; diff --git a/src/Controls/tests/TestCases.HostApp/FeatureMatrix/EntryControl/EntryControlPage.xaml.cs b/src/Controls/tests/TestCases.HostApp/FeatureMatrix/EntryControl/EntryControlPage.xaml.cs index 9f09e92d176f..2b1c2eeb4be7 100644 --- a/src/Controls/tests/TestCases.HostApp/FeatureMatrix/EntryControl/EntryControlPage.xaml.cs +++ b/src/Controls/tests/TestCases.HostApp/FeatureMatrix/EntryControl/EntryControlPage.xaml.cs @@ -5,121 +5,121 @@ namespace Maui.Controls.Sample; public class EntryControlPage : NavigationPage { - private EntryViewModel _viewModel; + private EntryViewModel _viewModel; - public EntryControlPage() - { - _viewModel = new EntryViewModel(); - PushAsync(new EntryControlMainPage(_viewModel)); - } + public EntryControlPage() + { + _viewModel = new EntryViewModel(); + PushAsync(new EntryControlMainPage(_viewModel)); + } } public partial class EntryControlMainPage : ContentPage { - private EntryViewModel _viewModel; - - public EntryControlMainPage(EntryViewModel viewModel) - { - InitializeComponent(); - _viewModel = viewModel; - BindingContext = _viewModel; - EntryControl.PropertyChanged += UpdateEntryControl; - } - - private async void NavigateToOptionsPage_Clicked(object sender, EventArgs e) - { - BindingContext = _viewModel = new EntryViewModel(); - _viewModel.Text = "Test Entry"; - _viewModel.Placeholder = "Enter text here"; - _viewModel.CursorPosition = 0; - _viewModel.SelectionLength = 0; - await Navigation.PushAsync(new EntryOptionsPage(_viewModel)); - } - - private void CursorPositionButton_Clicked(object sender, EventArgs e) - { - if (int.TryParse(CursorPositionEntry.Text, out int cursorPosition)) - { - _viewModel.CursorPosition = cursorPosition; - } - } - - private void SelectionLength_Clicked(object sender, EventArgs e) - { - if (int.TryParse(SelectionLengthEntry.Text, out int selectionLength)) - { - _viewModel.SelectionLength = selectionLength; - } - } - - private void OnUpdateCursorAndSelectionClicked(object sender, EventArgs e) - { - if (int.TryParse(CursorPositionEntry.Text, out int cursorPosition)) - { - EntryControl.Focus(); - EntryControl.CursorPosition = cursorPosition; - - if (BindingContext is EntryViewModel vm) - vm.CursorPosition = cursorPosition; - } - - if (int.TryParse(SelectionLengthEntry.Text, out int selectionLength)) - { - EntryControl.Focus(); - EntryControl.SelectionLength = selectionLength; - - if (BindingContext is EntryViewModel vm) - vm.SelectionLength = selectionLength; - } - CursorPositionEntry.Text = EntryControl.CursorPosition.ToString(); - SelectionLengthEntry.Text = EntryControl.SelectionLength.ToString(); - } - - void UpdateEntryControl(object sender, PropertyChangedEventArgs args) - { - if (args.PropertyName == Entry.CursorPositionProperty.PropertyName) - CursorPositionEntry.Text = EntryControl.CursorPosition.ToString(); - else if (args.PropertyName == Entry.SelectionLengthProperty.PropertyName) - SelectionLengthEntry.Text = EntryControl.SelectionLength.ToString(); - } - - private void EntryControl_TextChanged(object sender, TextChangedEventArgs e) - { - string eventInfo = $"TextChanged: Old='{e.OldTextValue}', New='{e.NewTextValue}'"; - - if (BindingContext is EntryViewModel vm) - { - vm.TextChangedText = eventInfo; - } - } - - private void EntryControl_Completed(object sender, EventArgs e) - { - string eventInfo = $"Completed: Event Triggered"; - - if (BindingContext is EntryViewModel vm) - { - vm.CompletedText = eventInfo; - } - } - - private void EntryControl_Focused(object sender, FocusEventArgs e) - { - string eventInfo = $"Focused: Event Triggered"; - - if (BindingContext is EntryViewModel vm) - { - vm.FocusedText = eventInfo; - } - } - - private void EntryControl_Unfocused(object sender, FocusEventArgs e) - { - string eventInfo = $"Unfocused: Event Triggered"; - - if (BindingContext is EntryViewModel vm) - { - vm.UnfocusedText = eventInfo; - } - } + private EntryViewModel _viewModel; + + public EntryControlMainPage(EntryViewModel viewModel) + { + InitializeComponent(); + _viewModel = viewModel; + BindingContext = _viewModel; + EntryControl.PropertyChanged += UpdateEntryControl; + } + + private async void NavigateToOptionsPage_Clicked(object sender, EventArgs e) + { + BindingContext = _viewModel = new EntryViewModel(); + _viewModel.Text = "Test Entry"; + _viewModel.Placeholder = "Enter text here"; + _viewModel.CursorPosition = 0; + _viewModel.SelectionLength = 0; + await Navigation.PushAsync(new EntryOptionsPage(_viewModel)); + } + + private void CursorPositionButton_Clicked(object sender, EventArgs e) + { + if (int.TryParse(CursorPositionEntry.Text, out int cursorPosition)) + { + _viewModel.CursorPosition = cursorPosition; + } + } + + private void SelectionLength_Clicked(object sender, EventArgs e) + { + if (int.TryParse(SelectionLengthEntry.Text, out int selectionLength)) + { + _viewModel.SelectionLength = selectionLength; + } + } + + private void OnUpdateCursorAndSelectionClicked(object sender, EventArgs e) + { + if (int.TryParse(CursorPositionEntry.Text, out int cursorPosition)) + { + EntryControl.Focus(); + EntryControl.CursorPosition = cursorPosition; + + if (BindingContext is EntryViewModel vm) + vm.CursorPosition = cursorPosition; + } + + if (int.TryParse(SelectionLengthEntry.Text, out int selectionLength)) + { + EntryControl.Focus(); + EntryControl.SelectionLength = selectionLength; + + if (BindingContext is EntryViewModel vm) + vm.SelectionLength = selectionLength; + } + CursorPositionEntry.Text = EntryControl.CursorPosition.ToString(); + SelectionLengthEntry.Text = EntryControl.SelectionLength.ToString(); + } + + void UpdateEntryControl(object sender, PropertyChangedEventArgs args) + { + if (args.PropertyName == Entry.CursorPositionProperty.PropertyName) + CursorPositionEntry.Text = EntryControl.CursorPosition.ToString(); + else if (args.PropertyName == Entry.SelectionLengthProperty.PropertyName) + SelectionLengthEntry.Text = EntryControl.SelectionLength.ToString(); + } + + private void EntryControl_TextChanged(object sender, TextChangedEventArgs e) + { + string eventInfo = $"TextChanged: Old='{e.OldTextValue}', New='{e.NewTextValue}'"; + + if (BindingContext is EntryViewModel vm) + { + vm.TextChangedText = eventInfo; + } + } + + private void EntryControl_Completed(object sender, EventArgs e) + { + string eventInfo = $"Completed: Event Triggered"; + + if (BindingContext is EntryViewModel vm) + { + vm.CompletedText = eventInfo; + } + } + + private void EntryControl_Focused(object sender, FocusEventArgs e) + { + string eventInfo = $"Focused: Event Triggered"; + + if (BindingContext is EntryViewModel vm) + { + vm.FocusedText = eventInfo; + } + } + + private void EntryControl_Unfocused(object sender, FocusEventArgs e) + { + string eventInfo = $"Unfocused: Event Triggered"; + + if (BindingContext is EntryViewModel vm) + { + vm.UnfocusedText = eventInfo; + } + } } \ No newline at end of file diff --git a/src/Controls/tests/TestCases.HostApp/FeatureMatrix/EntryControl/EntryOptionsPage.xaml.cs b/src/Controls/tests/TestCases.HostApp/FeatureMatrix/EntryControl/EntryOptionsPage.xaml.cs index 891d66cd34aa..3a446c554aca 100644 --- a/src/Controls/tests/TestCases.HostApp/FeatureMatrix/EntryControl/EntryOptionsPage.xaml.cs +++ b/src/Controls/tests/TestCases.HostApp/FeatureMatrix/EntryControl/EntryOptionsPage.xaml.cs @@ -1,274 +1,274 @@ -using Microsoft.Maui.Controls; -using System; +using System; +using Microsoft.Maui.Controls; namespace Maui.Controls.Sample; public partial class EntryOptionsPage : ContentPage { - private EntryViewModel _viewModel; + private EntryViewModel _viewModel; - public EntryOptionsPage(EntryViewModel viewModel) - { - InitializeComponent(); - _viewModel = viewModel; - BindingContext = _viewModel; - } + public EntryOptionsPage(EntryViewModel viewModel) + { + InitializeComponent(); + _viewModel = viewModel; + BindingContext = _viewModel; + } - private async void ApplyButton_Clicked(object sender, EventArgs e) - { - await Navigation.PopAsync(); - } + private async void ApplyButton_Clicked(object sender, EventArgs e) + { + await Navigation.PopAsync(); + } - private void TextColorButton_Clicked(object sender, EventArgs e) - { - if (sender is Button button) - { - _viewModel.TextColor = button.BackgroundColor; - } - } + private void TextColorButton_Clicked(object sender, EventArgs e) + { + if (sender is Button button) + { + _viewModel.TextColor = button.BackgroundColor; + } + } - private void Entry_TextChanged(object sender, TextChangedEventArgs e) - { - if (BindingContext is EntryViewModel vm) - { - vm.Text = e.NewTextValue; - } - } + private void Entry_TextChanged(object sender, TextChangedEventArgs e) + { + if (BindingContext is EntryViewModel vm) + { + vm.Text = e.NewTextValue; + } + } - private void PlaceholderEntry_TextChanged(object sender, TextChangedEventArgs e) - { - if (BindingContext is EntryViewModel vm) - { - vm.Placeholder = e.NewTextValue; - } - } + private void PlaceholderEntry_TextChanged(object sender, TextChangedEventArgs e) + { + if (BindingContext is EntryViewModel vm) + { + vm.Placeholder = e.NewTextValue; + } + } - private void PlaceholderColorButton_Clicked(object sender, EventArgs e) - { - if (sender is Button button) - { - _viewModel.PlaceholderColor = button.BackgroundColor; - } - } + private void PlaceholderColorButton_Clicked(object sender, EventArgs e) + { + if (sender is Button button) + { + _viewModel.PlaceholderColor = button.BackgroundColor; + } + } - private void ClearButtonVisibility_CheckedChanged(object sender, CheckedChangedEventArgs e) - { - if (sender == ClearButtonWhileEditing) - { - _viewModel.ClearButtonVisibility = ClearButtonVisibility.WhileEditing; - } - else if (sender == ClearButtonNever) - { - _viewModel.ClearButtonVisibility = ClearButtonVisibility.Never; - } - } + private void ClearButtonVisibility_CheckedChanged(object sender, CheckedChangedEventArgs e) + { + if (sender == ClearButtonWhileEditing) + { + _viewModel.ClearButtonVisibility = ClearButtonVisibility.WhileEditing; + } + else if (sender == ClearButtonNever) + { + _viewModel.ClearButtonVisibility = ClearButtonVisibility.Never; + } + } - private void HorizontalAlignmentButton_Clicked(object sender, EventArgs e) - { - if (sender is Button button) - { - _viewModel.HorizontalTextAlignment = button.AutomationId switch - { - "HStart" => TextAlignment.Start, - "HCenter" => TextAlignment.Center, - "HEnd" => TextAlignment.End, - _ => _viewModel.HorizontalTextAlignment - }; - } - } + private void HorizontalAlignmentButton_Clicked(object sender, EventArgs e) + { + if (sender is Button button) + { + _viewModel.HorizontalTextAlignment = button.AutomationId switch + { + "HStart" => TextAlignment.Start, + "HCenter" => TextAlignment.Center, + "HEnd" => TextAlignment.End, + _ => _viewModel.HorizontalTextAlignment + }; + } + } - private void VerticalAlignmentButton_Clicked(object sender, EventArgs e) - { - _viewModel.HeightRequest = 100; - if (sender is Button button) - { - _viewModel.VerticalTextAlignment = button.AutomationId switch - { - "VStart" => TextAlignment.Start, - "VCenter" => TextAlignment.Center, - "VEnd" => TextAlignment.End, - _ => _viewModel.VerticalTextAlignment - }; - } - } + private void VerticalAlignmentButton_Clicked(object sender, EventArgs e) + { + _viewModel.HeightRequest = 100; + if (sender is Button button) + { + _viewModel.VerticalTextAlignment = button.AutomationId switch + { + "VStart" => TextAlignment.Start, + "VCenter" => TextAlignment.Center, + "VEnd" => TextAlignment.End, + _ => _viewModel.VerticalTextAlignment + }; + } + } - private void IsPasswordTrueOrFalse_Clicked(object sender, EventArgs e) - { - if (IsPasswordTrue.IsChecked) - { - _viewModel.IsPassword = true; - } - else if (IsPasswordFalse.IsChecked) - { - _viewModel.IsPassword = false; - } - } + private void IsPasswordTrueOrFalse_Clicked(object sender, EventArgs e) + { + if (IsPasswordTrue.IsChecked) + { + _viewModel.IsPassword = true; + } + else if (IsPasswordFalse.IsChecked) + { + _viewModel.IsPassword = false; + } + } - private void ReturnTypeButton_Clicked(object sender, EventArgs e) - { - if (sender is Button button) - { - _viewModel.ReturnType = button.AutomationId switch - { - "Done" => ReturnType.Done, - "Next" => ReturnType.Next, - "Go" => ReturnType.Go, - "Search" => ReturnType.Search, - "Send" => ReturnType.Send, - "Default" => ReturnType.Default, - _ => _viewModel.ReturnType - }; - } - } + private void ReturnTypeButton_Clicked(object sender, EventArgs e) + { + if (sender is Button button) + { + _viewModel.ReturnType = button.AutomationId switch + { + "Done" => ReturnType.Done, + "Next" => ReturnType.Next, + "Go" => ReturnType.Go, + "Search" => ReturnType.Search, + "Send" => ReturnType.Send, + "Default" => ReturnType.Default, + _ => _viewModel.ReturnType + }; + } + } - private void MaxLengthButton_Clicked(object sender, EventArgs e) - { - if (int.TryParse(MaxLengthEntry.Text, out int maxLength)) - { - _viewModel.MaxLength = maxLength; - } - } + private void MaxLengthButton_Clicked(object sender, EventArgs e) + { + if (int.TryParse(MaxLengthEntry.Text, out int maxLength)) + { + _viewModel.MaxLength = maxLength; + } + } - private void FontSizeEntry_TextChanged(object sender, TextChangedEventArgs e) - { - if (double.TryParse(FontSizeEntry.Text, out double fontSize)) - { - _viewModel.FontSize = fontSize; - } - } + private void FontSizeEntry_TextChanged(object sender, TextChangedEventArgs e) + { + if (double.TryParse(FontSizeEntry.Text, out double fontSize)) + { + _viewModel.FontSize = fontSize; + } + } - private void CharacterSpacing_TextChanged(object sender, TextChangedEventArgs e) - { - if (double.TryParse(CharacterSpacingEntry.Text, out double characterSpacing)) - { - _viewModel.CharacterSpacing = characterSpacing; - } - } + private void CharacterSpacing_TextChanged(object sender, TextChangedEventArgs e) + { + if (double.TryParse(CharacterSpacingEntry.Text, out double characterSpacing)) + { + _viewModel.CharacterSpacing = characterSpacing; + } + } - private void IsReadOnlyTrueOrFalse_Clicked(object sender, EventArgs e) - { - if (IsReadOnlyTrue.IsChecked) - { - _viewModel.IsReadOnly = true; - } - else if (IsReadOnlyFalse.IsChecked) - { - _viewModel.IsReadOnly = false; - } - } + private void IsReadOnlyTrueOrFalse_Clicked(object sender, EventArgs e) + { + if (IsReadOnlyTrue.IsChecked) + { + _viewModel.IsReadOnly = true; + } + else if (IsReadOnlyFalse.IsChecked) + { + _viewModel.IsReadOnly = false; + } + } - private void IsTextPredictionEnabledTrueOrFalse_Clicked(object sender, EventArgs e) - { - if (IsTextPredictionEnabledTrue.IsChecked) - { - _viewModel.IsTextPredictionEnabled = true; - } - else if (IsTextPredictionEnabledFalse.IsChecked) - { - _viewModel.IsTextPredictionEnabled = false; - } - } + private void IsTextPredictionEnabledTrueOrFalse_Clicked(object sender, EventArgs e) + { + if (IsTextPredictionEnabledTrue.IsChecked) + { + _viewModel.IsTextPredictionEnabled = true; + } + else if (IsTextPredictionEnabledFalse.IsChecked) + { + _viewModel.IsTextPredictionEnabled = false; + } + } - private void IsSpellCheckEnabledTrueOrFalse_Clicked(object sender, EventArgs e) - { - if (IsSpellCheckEnabledTrue.IsChecked) - { - _viewModel.IsSpellCheckEnabled = true; - } - else if (IsSpellCheckEnabledFalse.IsChecked) - { - _viewModel.IsSpellCheckEnabled = false; - } - } + private void IsSpellCheckEnabledTrueOrFalse_Clicked(object sender, EventArgs e) + { + if (IsSpellCheckEnabledTrue.IsChecked) + { + _viewModel.IsSpellCheckEnabled = true; + } + else if (IsSpellCheckEnabledFalse.IsChecked) + { + _viewModel.IsSpellCheckEnabled = false; + } + } - private void KeyboardButton_Clicked(object sender, EventArgs e) - { - if (sender is Button button) - { - _viewModel.Keyboard = button.AutomationId switch - { - "Default" => Keyboard.Default, - "Chat" => Keyboard.Chat, - "Email" => Keyboard.Email, - "Numeric" => Keyboard.Numeric, - "Telephone" => Keyboard.Telephone, - "Text" => Keyboard.Text, - "Url" => Keyboard.Url, - _ => _viewModel.Keyboard - }; - } - } + private void KeyboardButton_Clicked(object sender, EventArgs e) + { + if (sender is Button button) + { + _viewModel.Keyboard = button.AutomationId switch + { + "Default" => Keyboard.Default, + "Chat" => Keyboard.Chat, + "Email" => Keyboard.Email, + "Numeric" => Keyboard.Numeric, + "Telephone" => Keyboard.Telephone, + "Text" => Keyboard.Text, + "Url" => Keyboard.Url, + _ => _viewModel.Keyboard + }; + } + } - private void FontFamilyEntry_TextChanged(object sender, TextChangedEventArgs e) - { - _viewModel.FontFamily = FontFamilyEntry.Text; - } + private void FontFamilyEntry_TextChanged(object sender, TextChangedEventArgs e) + { + _viewModel.FontFamily = FontFamilyEntry.Text; + } - private void FlowDirection_CheckedChanged(object sender, CheckedChangedEventArgs e) - { - if (sender == FlowDirectionLeftToRight) - { - _viewModel.FlowDirection = FlowDirection.LeftToRight; - } - else if (sender == FlowDirectionRightToLeft) - { - _viewModel.FlowDirection = FlowDirection.RightToLeft; - } - } + private void FlowDirection_CheckedChanged(object sender, CheckedChangedEventArgs e) + { + if (sender == FlowDirectionLeftToRight) + { + _viewModel.FlowDirection = FlowDirection.LeftToRight; + } + else if (sender == FlowDirectionRightToLeft) + { + _viewModel.FlowDirection = FlowDirection.RightToLeft; + } + } - private void IsVisibleTrueOrFalse_Clicked(object sender, EventArgs e) - { - if (IsVisibleTrue.IsChecked) - { - _viewModel.IsVisible = true; - } - else if (IsVisibleFalse.IsChecked) - { - _viewModel.IsVisible = false; - } - } + private void IsVisibleTrueOrFalse_Clicked(object sender, EventArgs e) + { + if (IsVisibleTrue.IsChecked) + { + _viewModel.IsVisible = true; + } + else if (IsVisibleFalse.IsChecked) + { + _viewModel.IsVisible = false; + } + } - private void IsEnabledTrueOrFalse_Clicked(object sender, EventArgs e) - { - if (IsEnabledTrue.IsChecked) - { - _viewModel.IsEnabled = true; - } - else if (IsEnabledFalse.IsChecked) - { - _viewModel.IsEnabled = false; - } - } + private void IsEnabledTrueOrFalse_Clicked(object sender, EventArgs e) + { + if (IsEnabledTrue.IsChecked) + { + _viewModel.IsEnabled = true; + } + else if (IsEnabledFalse.IsChecked) + { + _viewModel.IsEnabled = false; + } + } - private void TextTransform_CheckedChanged(object sender, CheckedChangedEventArgs e) - { - if (sender == TextTransformLowercase) - { - _viewModel.TextTransform = TextTransform.Lowercase; - } - else if (sender == TextTransformUppercase) - { - _viewModel.TextTransform = TextTransform.Uppercase; - } - else if (sender == TextTransformDefault) - { - _viewModel.TextTransform = TextTransform.Default; - } - } + private void TextTransform_CheckedChanged(object sender, CheckedChangedEventArgs e) + { + if (sender == TextTransformLowercase) + { + _viewModel.TextTransform = TextTransform.Lowercase; + } + else if (sender == TextTransformUppercase) + { + _viewModel.TextTransform = TextTransform.Uppercase; + } + else if (sender == TextTransformDefault) + { + _viewModel.TextTransform = TextTransform.Default; + } + } - private void FontAttributes_CheckedChanged(object sender, CheckedChangedEventArgs e) - { - if (sender == FontAttributesBold) - { - _viewModel.FontAttributes = FontAttributes.Bold; - } - else if (sender == FontAttributesNone) - { - _viewModel.FontAttributes = FontAttributes.None; - } - else if (sender == FontAttributesItalic) - { - _viewModel.FontAttributes = FontAttributes.Italic; - } - } + private void FontAttributes_CheckedChanged(object sender, CheckedChangedEventArgs e) + { + if (sender == FontAttributesBold) + { + _viewModel.FontAttributes = FontAttributes.Bold; + } + else if (sender == FontAttributesNone) + { + _viewModel.FontAttributes = FontAttributes.None; + } + else if (sender == FontAttributesItalic) + { + _viewModel.FontAttributes = FontAttributes.Italic; + } + } } \ No newline at end of file diff --git a/src/Controls/tests/TestCases.HostApp/FeatureMatrix/EntryControl/EntryViewModel.cs b/src/Controls/tests/TestCases.HostApp/FeatureMatrix/EntryControl/EntryViewModel.cs index 247be85eec5e..1cf67880874e 100644 --- a/src/Controls/tests/TestCases.HostApp/FeatureMatrix/EntryControl/EntryViewModel.cs +++ b/src/Controls/tests/TestCases.HostApp/FeatureMatrix/EntryControl/EntryViewModel.cs @@ -6,272 +6,272 @@ namespace Maui.Controls.Sample; public class EntryViewModel : INotifyPropertyChanged { - private string _text = "Test Entry"; - private Color _textColor = Colors.Black; - private string _placeholder = "Enter text here"; - private Color _placeholderColor = Colors.Gray; - private double _fontSize = 14; - private double _heightrequest = -1; - private TextAlignment _horizontalTextAlignment = TextAlignment.Start; - private TextAlignment _verticalTextAlignment = TextAlignment.Center; - private bool _isPassword = false; - private double _characterSpacing = 0; - private ReturnType _returnType = ReturnType.Default; - private int _maxLength = -1; - private int _cursorPosition = 0; - private int _selectionLength = 0; - private bool _isReadOnly = false; - private bool _isTextPredictionEnabled = false; - private bool _isSpellCheckEnabled = false; - private Keyboard _keyboard = Keyboard.Default; - private string _fontFamily = null; - private bool isVisible = true; - private bool _isEnabled = true; - private ClearButtonVisibility _clearButtonVisibility = ClearButtonVisibility.WhileEditing; - private FlowDirection _flowDirection = FlowDirection.LeftToRight; - private bool _hasShadow = false; - private Shadow _entryShadow = null; - private TextTransform _transform = TextTransform.Default; - private FontAttributes _fontAttributes = FontAttributes.None; - private string _textChangedText = "TextChanged: Not triggered"; - private string _completedText = "Completed: Not triggered"; - private string _focusedText = "Focused: Not triggered"; - private string _unfocusedText = "Unfocused: Not triggered"; + private string _text = "Test Entry"; + private Color _textColor = Colors.Black; + private string _placeholder = "Enter text here"; + private Color _placeholderColor = Colors.Gray; + private double _fontSize = 14; + private double _heightrequest = -1; + private TextAlignment _horizontalTextAlignment = TextAlignment.Start; + private TextAlignment _verticalTextAlignment = TextAlignment.Center; + private bool _isPassword = false; + private double _characterSpacing = 0; + private ReturnType _returnType = ReturnType.Default; + private int _maxLength = -1; + private int _cursorPosition = 0; + private int _selectionLength = 0; + private bool _isReadOnly = false; + private bool _isTextPredictionEnabled = false; + private bool _isSpellCheckEnabled = false; + private Keyboard _keyboard = Keyboard.Default; + private string _fontFamily = null; + private bool isVisible = true; + private bool _isEnabled = true; + private ClearButtonVisibility _clearButtonVisibility = ClearButtonVisibility.WhileEditing; + private FlowDirection _flowDirection = FlowDirection.LeftToRight; + private bool _hasShadow = false; + private Shadow _entryShadow = null; + private TextTransform _transform = TextTransform.Default; + private FontAttributes _fontAttributes = FontAttributes.None; + private string _textChangedText = "TextChanged: Not triggered"; + private string _completedText = "Completed: Not triggered"; + private string _focusedText = "Focused: Not triggered"; + private string _unfocusedText = "Unfocused: Not triggered"; - public event PropertyChangedEventHandler PropertyChanged; + public event PropertyChangedEventHandler PropertyChanged; - public ICommand ReturnCommand { get; set; } - public EntryViewModel() - { - ReturnCommand = new Command( - execute: (entryText) => - { - if (entryText == "Test") - { - Text = "Command Executed with Parameter"; - } - } - ); - } - public string Text - { - get => _text; - set { _text = value; OnPropertyChanged(); } - } + public ICommand ReturnCommand { get; set; } + public EntryViewModel() + { + ReturnCommand = new Command( + execute: (entryText) => + { + if (entryText == "Test") + { + Text = "Command Executed with Parameter"; + } + } + ); + } + public string Text + { + get => _text; + set { _text = value; OnPropertyChanged(); } + } - public Color TextColor - { - get => _textColor; - set { _textColor = value; OnPropertyChanged(); } - } + public Color TextColor + { + get => _textColor; + set { _textColor = value; OnPropertyChanged(); } + } - public string Placeholder - { - get => _placeholder; - set { _placeholder = value; OnPropertyChanged(); } - } - public Color PlaceholderColor - { - get => _placeholderColor; - set { _placeholderColor = value; OnPropertyChanged(); } - } + public string Placeholder + { + get => _placeholder; + set { _placeholder = value; OnPropertyChanged(); } + } + public Color PlaceholderColor + { + get => _placeholderColor; + set { _placeholderColor = value; OnPropertyChanged(); } + } - public ClearButtonVisibility ClearButtonVisibility - { - get => _clearButtonVisibility; - set { _clearButtonVisibility = value; OnPropertyChanged(); } - } + public ClearButtonVisibility ClearButtonVisibility + { + get => _clearButtonVisibility; + set { _clearButtonVisibility = value; OnPropertyChanged(); } + } - public double FontSize - { - get => _fontSize; - set { _fontSize = value; OnPropertyChanged(); } - } + public double FontSize + { + get => _fontSize; + set { _fontSize = value; OnPropertyChanged(); } + } - public double HeightRequest - { - get => _heightrequest; - set { _heightrequest = value; OnPropertyChanged(); } - } + public double HeightRequest + { + get => _heightrequest; + set { _heightrequest = value; OnPropertyChanged(); } + } - public TextAlignment HorizontalTextAlignment - { - get => _horizontalTextAlignment; - set { _horizontalTextAlignment = value; OnPropertyChanged(); } - } + public TextAlignment HorizontalTextAlignment + { + get => _horizontalTextAlignment; + set { _horizontalTextAlignment = value; OnPropertyChanged(); } + } - public TextAlignment VerticalTextAlignment - { - get => _verticalTextAlignment; - set { _verticalTextAlignment = value; OnPropertyChanged(); } - } + public TextAlignment VerticalTextAlignment + { + get => _verticalTextAlignment; + set { _verticalTextAlignment = value; OnPropertyChanged(); } + } - public bool IsPassword - { - get => _isPassword; - set { _isPassword = value; OnPropertyChanged(); } - } + public bool IsPassword + { + get => _isPassword; + set { _isPassword = value; OnPropertyChanged(); } + } - public double CharacterSpacing - { - get => _characterSpacing; - set { _characterSpacing = value; OnPropertyChanged(); } - } + public double CharacterSpacing + { + get => _characterSpacing; + set { _characterSpacing = value; OnPropertyChanged(); } + } - public ReturnType ReturnType - { - get => _returnType; - set { _returnType = value; OnPropertyChanged(); } - } + public ReturnType ReturnType + { + get => _returnType; + set { _returnType = value; OnPropertyChanged(); } + } - public int MaxLength - { - get => _maxLength; - set { _maxLength = value; OnPropertyChanged(); } - } - public int CursorPosition - { - get => _cursorPosition; - set { _cursorPosition = value; OnPropertyChanged(); } - } - public int SelectionLength - { - get => _selectionLength; - set { _selectionLength = value; OnPropertyChanged(); } - } - public bool IsReadOnly - { - get => _isReadOnly; - set { _isReadOnly = value; OnPropertyChanged(); } - } - public bool IsTextPredictionEnabled - { - get => _isTextPredictionEnabled; - set { _isTextPredictionEnabled = value; OnPropertyChanged(); } - } - public bool IsSpellCheckEnabled - { - get => _isSpellCheckEnabled; - set { _isSpellCheckEnabled = value; OnPropertyChanged(); } - } + public int MaxLength + { + get => _maxLength; + set { _maxLength = value; OnPropertyChanged(); } + } + public int CursorPosition + { + get => _cursorPosition; + set { _cursorPosition = value; OnPropertyChanged(); } + } + public int SelectionLength + { + get => _selectionLength; + set { _selectionLength = value; OnPropertyChanged(); } + } + public bool IsReadOnly + { + get => _isReadOnly; + set { _isReadOnly = value; OnPropertyChanged(); } + } + public bool IsTextPredictionEnabled + { + get => _isTextPredictionEnabled; + set { _isTextPredictionEnabled = value; OnPropertyChanged(); } + } + public bool IsSpellCheckEnabled + { + get => _isSpellCheckEnabled; + set { _isSpellCheckEnabled = value; OnPropertyChanged(); } + } - public bool IsVisible - { - get => isVisible; - set { isVisible = value; OnPropertyChanged(); } - } + public bool IsVisible + { + get => isVisible; + set { isVisible = value; OnPropertyChanged(); } + } - public bool IsEnabled - { - get => _isEnabled; - set { _isEnabled = value; OnPropertyChanged(); } - } + public bool IsEnabled + { + get => _isEnabled; + set { _isEnabled = value; OnPropertyChanged(); } + } - public Keyboard Keyboard - { - get => _keyboard; - set { _keyboard = value; OnPropertyChanged(); } - } + public Keyboard Keyboard + { + get => _keyboard; + set { _keyboard = value; OnPropertyChanged(); } + } - public FlowDirection FlowDirection - { - get => _flowDirection; - set { _flowDirection = value; OnPropertyChanged(); } - } + public FlowDirection FlowDirection + { + get => _flowDirection; + set { _flowDirection = value; OnPropertyChanged(); } + } - public string FontFamily - { - get => _fontFamily; - set { _fontFamily = value; OnPropertyChanged(); } - } + public string FontFamily + { + get => _fontFamily; + set { _fontFamily = value; OnPropertyChanged(); } + } - public string TextChangedText - { - get => _textChangedText; - set { _textChangedText = value; OnPropertyChanged(); } - } + public string TextChangedText + { + get => _textChangedText; + set { _textChangedText = value; OnPropertyChanged(); } + } - public string CompletedText - { - get => _completedText; - set { _completedText = value; OnPropertyChanged(); } - } + public string CompletedText + { + get => _completedText; + set { _completedText = value; OnPropertyChanged(); } + } - public string FocusedText - { - get => _focusedText; - set { _focusedText = value; OnPropertyChanged(); } - } + public string FocusedText + { + get => _focusedText; + set { _focusedText = value; OnPropertyChanged(); } + } - public string UnfocusedText - { - get => _unfocusedText; - set { _unfocusedText = value; OnPropertyChanged(); } - } + public string UnfocusedText + { + get => _unfocusedText; + set { _unfocusedText = value; OnPropertyChanged(); } + } - public bool HasShadow - { - get => _hasShadow; - set - { - if (_hasShadow != value) - { - _hasShadow = value; - EntryShadow = value - ? new Shadow - { - Radius = 10, - Opacity = 1.0f, - Brush = Colors.Black.AsPaint(), - Offset = new Point(5, 5) - } - : null; - OnPropertyChanged(nameof(HasShadow)); - } - } - } + public bool HasShadow + { + get => _hasShadow; + set + { + if (_hasShadow != value) + { + _hasShadow = value; + EntryShadow = value + ? new Shadow + { + Radius = 10, + Opacity = 1.0f, + Brush = Colors.Black.AsPaint(), + Offset = new Point(5, 5) + } + : null; + OnPropertyChanged(nameof(HasShadow)); + } + } + } - public Shadow EntryShadow - { - get => _entryShadow; - private set - { - if (_entryShadow != value) - { - _entryShadow = value; - OnPropertyChanged(nameof(EntryShadow)); - } - } - } + public Shadow EntryShadow + { + get => _entryShadow; + private set + { + if (_entryShadow != value) + { + _entryShadow = value; + OnPropertyChanged(nameof(EntryShadow)); + } + } + } - public TextTransform TextTransform - { - get => _transform; - set - { - if (_transform != value) - { - _transform = value; - OnPropertyChanged(nameof(TextTransform)); - } - } - } + public TextTransform TextTransform + { + get => _transform; + set + { + if (_transform != value) + { + _transform = value; + OnPropertyChanged(nameof(TextTransform)); + } + } + } - public FontAttributes FontAttributes - { - get => _fontAttributes; - set - { - if (_fontAttributes != value) - { - _fontAttributes = value; - OnPropertyChanged(nameof(FontAttributes)); - } - } - } + public FontAttributes FontAttributes + { + get => _fontAttributes; + set + { + if (_fontAttributes != value) + { + _fontAttributes = value; + OnPropertyChanged(nameof(FontAttributes)); + } + } + } - protected void OnPropertyChanged([CallerMemberName] string propertyName = null) - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } + protected void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } } \ No newline at end of file diff --git a/src/Controls/tests/TestCases.HostApp/FeatureMatrix/Switch/SwitchViewModel.cs b/src/Controls/tests/TestCases.HostApp/FeatureMatrix/Switch/SwitchViewModel.cs index a37890dbefb7..c601800ab206 100644 --- a/src/Controls/tests/TestCases.HostApp/FeatureMatrix/Switch/SwitchViewModel.cs +++ b/src/Controls/tests/TestCases.HostApp/FeatureMatrix/Switch/SwitchViewModel.cs @@ -6,109 +6,109 @@ namespace Maui.Controls.Sample; public class SwitchViewModel : INotifyPropertyChanged { - private FlowDirection _flowDirection = FlowDirection.LeftToRight; - private bool _isEnabled = true; - private bool _isVisible = true; - private bool _isToggled = false; - private Color _onColor; - private Shadow _shadow; - private Color _thumbColor; + private FlowDirection _flowDirection = FlowDirection.LeftToRight; + private bool _isEnabled = true; + private bool _isVisible = true; + private bool _isToggled = false; + private Color _onColor; + private Shadow _shadow; + private Color _thumbColor; - public FlowDirection FlowDirection - { - get => _flowDirection; - set - { - if (_flowDirection != value) - { - _flowDirection = value; - OnPropertyChanged(); - } - } - } + public FlowDirection FlowDirection + { + get => _flowDirection; + set + { + if (_flowDirection != value) + { + _flowDirection = value; + OnPropertyChanged(); + } + } + } - public bool IsEnabled - { - get => _isEnabled; - set - { - if (_isEnabled != value) - { - _isEnabled = value; - OnPropertyChanged(); - } - } - } + public bool IsEnabled + { + get => _isEnabled; + set + { + if (_isEnabled != value) + { + _isEnabled = value; + OnPropertyChanged(); + } + } + } - public bool IsVisible - { - get => _isVisible; - set - { - if (_isVisible != value) - { - _isVisible = value; - OnPropertyChanged(); - } - } - } + public bool IsVisible + { + get => _isVisible; + set + { + if (_isVisible != value) + { + _isVisible = value; + OnPropertyChanged(); + } + } + } - public bool IsToggled - { - get => _isToggled; - set - { - if (_isToggled != value) - { - _isToggled = value; - OnPropertyChanged(); - } - } - } + public bool IsToggled + { + get => _isToggled; + set + { + if (_isToggled != value) + { + _isToggled = value; + OnPropertyChanged(); + } + } + } - public Color OnColor - { - get => _onColor; - set - { - if (_onColor != value) - { - _onColor = value; - OnPropertyChanged(); - } - } - } + public Color OnColor + { + get => _onColor; + set + { + if (_onColor != value) + { + _onColor = value; + OnPropertyChanged(); + } + } + } - public Shadow Shadow - { - get => _shadow; - set - { - if (_shadow != value) - { - _shadow = value; - OnPropertyChanged(); - } - } - } + public Shadow Shadow + { + get => _shadow; + set + { + if (_shadow != value) + { + _shadow = value; + OnPropertyChanged(); + } + } + } - public Color ThumbColor - { - get => _thumbColor; - set - { - if (_thumbColor != value) - { - _thumbColor = value; - OnPropertyChanged(); - } - } - } + public Color ThumbColor + { + get => _thumbColor; + set + { + if (_thumbColor != value) + { + _thumbColor = value; + OnPropertyChanged(); + } + } + } - public event PropertyChangedEventHandler PropertyChanged; + public event PropertyChangedEventHandler PropertyChanged; - protected void OnPropertyChanged([CallerMemberName] string propertyName = null) - { - PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); - } + protected void OnPropertyChanged([CallerMemberName] string propertyName = null) + { + PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName)); + } } diff --git a/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla21177.cs b/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla21177.cs index d0a948c1bae9..130f2fbd11d4 100644 --- a/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla21177.cs +++ b/src/Controls/tests/TestCases.HostApp/Issues/Bugzilla/Bugzilla21177.cs @@ -10,10 +10,7 @@ public class CollectionView : View public void InvokeItemSelected(int index) { - if (ItemSelected != null) - { - ItemSelected.Invoke(this, index); - } + ItemSelected?.Invoke(this, index); } } diff --git a/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/SwitchFeatureTests.cs b/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/SwitchFeatureTests.cs index 4f1fb28ef8b7..8e5a3e055b08 100644 --- a/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/SwitchFeatureTests.cs +++ b/src/Controls/tests/TestCases.Shared.Tests/Tests/FeatureMatrix/SwitchFeatureTests.cs @@ -7,114 +7,114 @@ namespace Microsoft.Maui.TestCases.Tests; public class SwitchFeatureTests : UITest { - public const string SwitchFeatureMatrix = "Switch Feature Matrix"; + public const string SwitchFeatureMatrix = "Switch Feature Matrix"; - public SwitchFeatureTests(TestDevice device) - : base(device) - { - } + public SwitchFeatureTests(TestDevice device) + : base(device) + { + } - protected override void FixtureSetup() - { - base.FixtureSetup(); - App.NavigateToGallery(SwitchFeatureMatrix); - } + protected override void FixtureSetup() + { + base.FixtureSetup(); + App.NavigateToGallery(SwitchFeatureMatrix); + } - [Test, Order(1)] - [Category(UITestCategories.Switch)] - public void Switch_InitialState_VerifyVisualState() - { - App.WaitForElement("SwitchControl"); - VerifyScreenshot(); - } + [Test, Order(1)] + [Category(UITestCategories.Switch)] + public void Switch_InitialState_VerifyVisualState() + { + App.WaitForElement("SwitchControl"); + VerifyScreenshot(); + } - [Test, Order(2)] - [Category(UITestCategories.Switch)] - public void Switch_Click_VerifyVisualState() - { - App.WaitForElement("SwitchControl"); - App.Tap("SwitchControl"); - VerifyScreenshot(); - } + [Test, Order(2)] + [Category(UITestCategories.Switch)] + public void Switch_Click_VerifyVisualState() + { + App.WaitForElement("SwitchControl"); + App.Tap("SwitchControl"); + VerifyScreenshot(); + } - [Test] - [Category(UITestCategories.Switch)] - public void Switch_SetFlowDirectionAndToggled_VerifyVisualState() - { - App.WaitForElement("Options"); - App.Tap("Options"); - App.WaitForElement("FlowDirectionRightToLeftCheckBox"); - App.Tap("FlowDirectionRightToLeftCheckBox"); - App.WaitForElement("Apply"); - App.Tap("Apply"); - App.WaitForElement("SwitchControl"); - App.Tap("SwitchControl"); - VerifyScreenshot(); - } + [Test] + [Category(UITestCategories.Switch)] + public void Switch_SetFlowDirectionAndToggled_VerifyVisualState() + { + App.WaitForElement("Options"); + App.Tap("Options"); + App.WaitForElement("FlowDirectionRightToLeftCheckBox"); + App.Tap("FlowDirectionRightToLeftCheckBox"); + App.WaitForElement("Apply"); + App.Tap("Apply"); + App.WaitForElement("SwitchControl"); + App.Tap("SwitchControl"); + VerifyScreenshot(); + } - [Test] - [Category(UITestCategories.Switch)] - public void Switch_SetEnabled_VerifyVisualState() - { - App.WaitForElement("Options"); - App.Tap("Options"); - App.WaitForElement("IsEnabledFalseCheckBox"); - App.Tap("IsEnabledFalseCheckBox"); - App.WaitForElement("Apply"); - App.Tap("Apply"); - App.WaitForElement("SwitchControl"); - App.Tap("SwitchControl"); - App.WaitForElement("ToggledEventLabel"); - Assert.That(App.FindElement("ToggledEventLabel").GetText(), Is.EqualTo("False")); - } + [Test] + [Category(UITestCategories.Switch)] + public void Switch_SetEnabled_VerifyVisualState() + { + App.WaitForElement("Options"); + App.Tap("Options"); + App.WaitForElement("IsEnabledFalseCheckBox"); + App.Tap("IsEnabledFalseCheckBox"); + App.WaitForElement("Apply"); + App.Tap("Apply"); + App.WaitForElement("SwitchControl"); + App.Tap("SwitchControl"); + App.WaitForElement("ToggledEventLabel"); + Assert.That(App.FindElement("ToggledEventLabel").GetText(), Is.EqualTo("False")); + } - [Test] - [Category(UITestCategories.Switch)] - public void Switch_SetVisibleAndToggled_VerifyVisualState() - { - App.WaitForElement("Options"); - App.Tap("Options"); - App.WaitForElement("IsVisibleFalseCheckBox"); - App.Tap("IsVisibleFalseCheckBox"); - App.WaitForElement("IsToggledTrueCheckBox"); - App.Tap("IsToggledTrueCheckBox"); - App.WaitForElement("Apply"); - App.Tap("Apply"); - App.WaitForNoElement("SwitchControl"); - } + [Test] + [Category(UITestCategories.Switch)] + public void Switch_SetVisibleAndToggled_VerifyVisualState() + { + App.WaitForElement("Options"); + App.Tap("Options"); + App.WaitForElement("IsVisibleFalseCheckBox"); + App.Tap("IsVisibleFalseCheckBox"); + App.WaitForElement("IsToggledTrueCheckBox"); + App.Tap("IsToggledTrueCheckBox"); + App.WaitForElement("Apply"); + App.Tap("Apply"); + App.WaitForNoElement("SwitchControl"); + } - [Test] - [Category(UITestCategories.Switch)] - public void Switch_SetToggledAndOnColor_VerifyVisualState() - { - App.WaitForElement("Options"); - App.Tap("Options"); - App.WaitForElement("IsToggledTrueCheckBox"); - App.Tap("IsToggledTrueCheckBox"); - App.WaitForElement("OnColorRedCheckBox"); - App.Tap("OnColorRedCheckBox"); - App.WaitForElement("Apply"); - App.Tap("Apply"); - App.WaitForElementTillPageNavigationSettled("SwitchControl"); - VerifyScreenshot(); - } + [Test] + [Category(UITestCategories.Switch)] + public void Switch_SetToggledAndOnColor_VerifyVisualState() + { + App.WaitForElement("Options"); + App.Tap("Options"); + App.WaitForElement("IsToggledTrueCheckBox"); + App.Tap("IsToggledTrueCheckBox"); + App.WaitForElement("OnColorRedCheckBox"); + App.Tap("OnColorRedCheckBox"); + App.WaitForElement("Apply"); + App.Tap("Apply"); + App.WaitForElementTillPageNavigationSettled("SwitchControl"); + VerifyScreenshot(); + } - [Test] - [Category(UITestCategories.Switch)] - public void Switch_SetOnColorAndThumbColor_VerifyVisualState() - { - App.WaitForElement("Options"); - App.Tap("Options"); - App.WaitForElement("OnColorRedCheckBox"); - App.Tap("OnColorRedCheckBox"); - App.WaitForElement("ThumbColorGreenCheckBox"); - App.Tap("ThumbColorGreenCheckBox"); - App.WaitForElement("Apply"); - App.Tap("Apply"); - App.WaitForElement("SwitchControl"); - App.Tap("SwitchControl"); - VerifyScreenshot(); - } + [Test] + [Category(UITestCategories.Switch)] + public void Switch_SetOnColorAndThumbColor_VerifyVisualState() + { + App.WaitForElement("Options"); + App.Tap("Options"); + App.WaitForElement("OnColorRedCheckBox"); + App.Tap("OnColorRedCheckBox"); + App.WaitForElement("ThumbColorGreenCheckBox"); + App.Tap("ThumbColorGreenCheckBox"); + App.WaitForElement("Apply"); + App.Tap("Apply"); + App.WaitForElement("SwitchControl"); + App.Tap("SwitchControl"); + VerifyScreenshot(); + } #if TEST_FAILS_ON_ANDROID && TEST_FAILS_ON_WINDOWS // Issue Link - https://github.com/dotnet/maui/issues/30046, https://github.com/dotnet/maui/issues/29812 [Test] @@ -172,20 +172,20 @@ public void Switch_SetShadowAndThumbColor_VerifyVisualState() } #endif - [Test] - [Category(UITestCategories.Switch)] - public void Switch_SetThumbColorAndOnColor_VerifyVisualState() - { - App.WaitForElement("Options"); - App.Tap("Options"); - App.WaitForElement("ThumbColorRedCheckBox"); - App.Tap("ThumbColorRedCheckBox"); - App.WaitForElement("OnColorGreenCheckBox"); - App.Tap("OnColorGreenCheckBox"); - App.WaitForElement("Apply"); - App.Tap("Apply"); - App.WaitForElement("SwitchControl"); - App.Tap("SwitchControl"); - VerifyScreenshot(); - } + [Test] + [Category(UITestCategories.Switch)] + public void Switch_SetThumbColorAndOnColor_VerifyVisualState() + { + App.WaitForElement("Options"); + App.Tap("Options"); + App.WaitForElement("ThumbColorRedCheckBox"); + App.Tap("ThumbColorRedCheckBox"); + App.WaitForElement("OnColorGreenCheckBox"); + App.Tap("OnColorGreenCheckBox"); + App.WaitForElement("Apply"); + App.Tap("Apply"); + App.WaitForElement("SwitchControl"); + App.Tap("SwitchControl"); + VerifyScreenshot(); + } } \ No newline at end of file diff --git a/src/Controls/tests/Xaml.UnitTests/LoaderTests.cs b/src/Controls/tests/Xaml.UnitTests/LoaderTests.cs index 995c78e1172b..01c9e6d4e01c 100644 --- a/src/Controls/tests/Xaml.UnitTests/LoaderTests.cs +++ b/src/Controls/tests/Xaml.UnitTests/LoaderTests.cs @@ -63,8 +63,7 @@ public class Catalog propertyChanged: (bindable, oldvalue, newvalue) => { var label = bindable as Label; - if (label != null) - label.SetValue(Label.TextProperty, new string(((string)newvalue).Reverse().ToArray())); + label?.SetValue(Label.TextProperty, new string(((string)newvalue).Reverse().ToArray())); }); public static string GetMessage(BindableObject bindable) diff --git a/src/Core/src/Handlers/Border/BorderHandler.cs b/src/Core/src/Handlers/Border/BorderHandler.cs index 3768817cda15..5f66af4af534 100644 --- a/src/Core/src/Handlers/Border/BorderHandler.cs +++ b/src/Core/src/Handlers/Border/BorderHandler.cs @@ -88,7 +88,8 @@ public static void MapBackground(IBorderHandler handler, IBorderView border) } [MethodImpl(MethodImplOptions.AggressiveInlining)] - private static bool ShouldSkipStrokeMappings(IBorderHandler handler) { + private static bool ShouldSkipStrokeMappings(IBorderHandler handler) + { #if __IOS__ || MACCATALYST || ANDROID // During the initial connection, the `MapBackground` takes care of updating the stroke properties // so we can skip the stroke mappings to avoid repetitive and useless updates. diff --git a/src/Core/src/Handlers/FlyoutView/FlyoutViewHandler.Android.cs b/src/Core/src/Handlers/FlyoutView/FlyoutViewHandler.Android.cs index 7a485f7b49ab..85c53c1d9a2f 100644 --- a/src/Core/src/Handlers/FlyoutView/FlyoutViewHandler.Android.cs +++ b/src/Core/src/Handlers/FlyoutView/FlyoutViewHandler.Android.cs @@ -124,8 +124,7 @@ void UpdateFlyout() if (_flyoutView == newFlyoutView) return; - if (_flyoutView != null) - _flyoutView.RemoveFromParent(); + _flyoutView?.RemoveFromParent(); _flyoutView = newFlyoutView; if (_flyoutView == null) diff --git a/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.Android.cs b/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.Android.cs index cfa5c7ebb9a0..eabc4383037b 100644 --- a/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.Android.cs +++ b/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.Android.cs @@ -72,8 +72,7 @@ public static void MapBackground(ISwipeItemMenuItemHandler handler, ISwipeItemMe public static void MapVisibility(ISwipeItemMenuItemHandler handler, ISwipeItemMenuItem view) { var swipeView = handler.PlatformView.Parent.GetParentOfType(); - if (swipeView != null) - swipeView.UpdateIsVisibleSwipeItem(view); + swipeView?.UpdateIsVisibleSwipeItem(view); handler.PlatformView.Visibility = view.Visibility.ToPlatformVisibility(); } diff --git a/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.Tizen.cs b/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.Tizen.cs index 1208d743b2ba..5e7156491f05 100644 --- a/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.Tizen.cs +++ b/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.Tizen.cs @@ -53,8 +53,7 @@ public static void MapVisibility(ISwipeItemMenuItemHandler handler, ISwipeItemMe } var swipeView = handler.PlatformView.GetParentOfType(); - if (swipeView != null) - swipeView.UpdateIsVisibleSwipeItem(view); + swipeView?.UpdateIsVisibleSwipeItem(view); } partial class SwipeItemMenuItemImageSourcePartSetter diff --git a/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.iOS.cs b/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.iOS.cs index 505e90e40160..36b67d1433dd 100644 --- a/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.iOS.cs +++ b/src/Core/src/Handlers/SwipeItemMenuItem/SwipeItemMenuItemHandler.iOS.cs @@ -88,8 +88,7 @@ public static void MapVisibility(ISwipeItemMenuItemHandler handler, ISwipeItemMe { var swipeView = handler.PlatformView.GetParentOfType(); - if (swipeView != null) - swipeView.UpdateIsVisibleSwipeItem(view); + swipeView?.UpdateIsVisibleSwipeItem(view); handler.PlatformView.UpdateVisibility(view.Visibility); } diff --git a/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.Android.cs b/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.Android.cs index 99d49ecc0053..3a56b8d73cdf 100644 --- a/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.Android.cs +++ b/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.Android.cs @@ -50,8 +50,7 @@ public static void MapContent(ISwipeItemViewHandler handler, ISwipeItemView page public static void MapVisibility(ISwipeItemViewHandler handler, ISwipeItemView view) { var swipeView = handler.PlatformView?.Parent.GetParentOfType(); - if (swipeView != null) - swipeView.UpdateIsVisibleSwipeItem(view); + swipeView?.UpdateIsVisibleSwipeItem(view); } protected override void DisconnectHandler(ContentViewGroup platformView) diff --git a/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.Tizen.cs b/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.Tizen.cs index 7ec793c638c4..4926d034b721 100644 --- a/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.Tizen.cs +++ b/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.Tizen.cs @@ -68,8 +68,7 @@ public static void MapVisibility(ISwipeItemViewHandler handler, ISwipeItemView v handler.PlatformView.UpdateVisibility(view); var swipeView = handler.PlatformView.GetParentOfType(); - if (swipeView != null) - swipeView.UpdateIsVisibleSwipeItem(view); + swipeView?.UpdateIsVisibleSwipeItem(view); } } } diff --git a/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.iOS.cs b/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.iOS.cs index c455d94a3f88..747a390f1f69 100644 --- a/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.iOS.cs +++ b/src/Core/src/Handlers/SwipeItemView/SwipeItemViewHandler.iOS.cs @@ -44,8 +44,7 @@ public static void MapContent(ISwipeItemViewHandler handler, ISwipeItemView page public static void MapVisibility(ISwipeItemViewHandler handler, ISwipeItemView view) { var swipeView = handler.PlatformView.GetParentOfType(); - if (swipeView != null) - swipeView.UpdateIsVisibleSwipeItem(view); + swipeView?.UpdateIsVisibleSwipeItem(view); handler.PlatformView.UpdateVisibility(view.Visibility); } diff --git a/src/Core/src/Handlers/TimePicker/TimePickerHandler.Android.cs b/src/Core/src/Handlers/TimePicker/TimePickerHandler.Android.cs index f3a807167be8..8d148d3c5cbb 100644 --- a/src/Core/src/Handlers/TimePicker/TimePickerHandler.Android.cs +++ b/src/Core/src/Handlers/TimePicker/TimePickerHandler.Android.cs @@ -105,10 +105,7 @@ void ShowPickerDialog(int hour, int minute) void HidePickerDialog() { - if (_dialog != null) - { - _dialog.Hide(); - } + _dialog?.Hide(); _dialog = null; } diff --git a/src/Core/src/Handlers/View/ViewHandler.Windows.cs b/src/Core/src/Handlers/View/ViewHandler.Windows.cs index ac91b3e424c8..1c760bd798a4 100644 --- a/src/Core/src/Handlers/View/ViewHandler.Windows.cs +++ b/src/Core/src/Handlers/View/ViewHandler.Windows.cs @@ -112,7 +112,8 @@ public static void MapContextFlyout(IViewHandler handler, IView view) { if (view is IContextFlyoutElement contextFlyoutContainer) { - if (handler.IsConnectingHandler() && contextFlyoutContainer.ContextFlyout is null) return; + if (handler.IsConnectingHandler() && contextFlyoutContainer.ContextFlyout is null) + return; MapContextFlyout(handler, contextFlyoutContainer); } diff --git a/src/Core/src/Handlers/View/ViewHandler.cs b/src/Core/src/Handlers/View/ViewHandler.cs index a7a995462770..4f0562c097f1 100644 --- a/src/Core/src/Handlers/View/ViewHandler.cs +++ b/src/Core/src/Handlers/View/ViewHandler.cs @@ -422,7 +422,8 @@ public static void MapOpacity(IViewHandler handler, IView view) return; } #else - if (handler.IsConnectingHandler() && view.Opacity == 1) return; + if (handler.IsConnectingHandler() && view.Opacity == 1) + return; #endif if (handler.HasContainer) @@ -442,7 +443,8 @@ public static void MapOpacity(IViewHandler handler, IView view) /// The associated instance. public static void MapAutomationId(IViewHandler handler, IView view) { - if (handler.IsConnectingHandler() && view.AutomationId is null) return; + if (handler.IsConnectingHandler() && view.AutomationId is null) + return; ((PlatformView?)handler.PlatformView)?.UpdateAutomationId(view); } @@ -454,7 +456,8 @@ public static void MapAutomationId(IViewHandler handler, IView view) /// The associated instance. public static void MapClip(IViewHandler handler, IView view) { - if (handler.IsConnectingHandler() && view.Clip is null) return; + if (handler.IsConnectingHandler() && view.Clip is null) + return; if (!handler.IsMappingProperties()) { @@ -472,7 +475,8 @@ public static void MapClip(IViewHandler handler, IView view) /// The associated instance. public static void MapShadow(IViewHandler handler, IView view) { - if (handler.IsConnectingHandler() && view.Shadow is null) return; + if (handler.IsConnectingHandler() && view.Shadow is null) + return; if (!handler.IsMappingProperties()) { diff --git a/src/Core/src/Handlers/View/ViewHandler.iOS.cs b/src/Core/src/Handlers/View/ViewHandler.iOS.cs index 501404384f76..03198d86ea5f 100644 --- a/src/Core/src/Handlers/View/ViewHandler.iOS.cs +++ b/src/Core/src/Handlers/View/ViewHandler.iOS.cs @@ -60,7 +60,8 @@ static partial void MappingFrame(IViewHandler handler, IView view) public static void MapTranslationX(IViewHandler handler, IView view) { // During the initial setup, MappingFrame will take care of everything - if (handler.IsConnectingHandler()) return; + if (handler.IsConnectingHandler()) + return; UpdateTransformation(handler, view); } @@ -68,7 +69,8 @@ public static void MapTranslationX(IViewHandler handler, IView view) public static void MapTranslationY(IViewHandler handler, IView view) { // During the initial setup, MappingFrame will take care of everything - if (handler.IsConnectingHandler()) return; + if (handler.IsConnectingHandler()) + return; UpdateTransformation(handler, view); } @@ -76,7 +78,8 @@ public static void MapTranslationY(IViewHandler handler, IView view) public static void MapScale(IViewHandler handler, IView view) { // During the initial setup, MappingFrame will take care of everything - if (handler.IsConnectingHandler()) return; + if (handler.IsConnectingHandler()) + return; UpdateTransformation(handler, view); } @@ -84,7 +87,8 @@ public static void MapScale(IViewHandler handler, IView view) public static void MapScaleX(IViewHandler handler, IView view) { // During the initial setup, MappingFrame will take care of everything - if (handler.IsConnectingHandler()) return; + if (handler.IsConnectingHandler()) + return; UpdateTransformation(handler, view); } @@ -92,7 +96,8 @@ public static void MapScaleX(IViewHandler handler, IView view) public static void MapScaleY(IViewHandler handler, IView view) { // During the initial setup, MappingFrame will take care of everything - if (handler.IsConnectingHandler()) return; + if (handler.IsConnectingHandler()) + return; UpdateTransformation(handler, view); } @@ -100,7 +105,8 @@ public static void MapScaleY(IViewHandler handler, IView view) public static void MapRotation(IViewHandler handler, IView view) { // During the initial setup, MappingFrame will take care of everything - if (handler.IsConnectingHandler()) return; + if (handler.IsConnectingHandler()) + return; UpdateTransformation(handler, view); } @@ -108,7 +114,8 @@ public static void MapRotation(IViewHandler handler, IView view) public static void MapRotationX(IViewHandler handler, IView view) { // During the initial setup, MappingFrame will take care of everything - if (handler.IsConnectingHandler()) return; + if (handler.IsConnectingHandler()) + return; UpdateTransformation(handler, view); } @@ -116,7 +123,8 @@ public static void MapRotationX(IViewHandler handler, IView view) public static void MapRotationY(IViewHandler handler, IView view) { // During the initial setup, MappingFrame will take care of everything - if (handler.IsConnectingHandler()) return; + if (handler.IsConnectingHandler()) + return; UpdateTransformation(handler, view); } @@ -124,7 +132,8 @@ public static void MapRotationY(IViewHandler handler, IView view) public static void MapAnchorX(IViewHandler handler, IView view) { // During the initial setup, MappingFrame will take care of everything - if (handler.IsConnectingHandler()) return; + if (handler.IsConnectingHandler()) + return; UpdateTransformation(handler, view); } @@ -132,7 +141,8 @@ public static void MapAnchorX(IViewHandler handler, IView view) public static void MapAnchorY(IViewHandler handler, IView view) { // During the initial setup, MappingFrame will take care of everything - if (handler.IsConnectingHandler()) return; + if (handler.IsConnectingHandler()) + return; UpdateTransformation(handler, view); } diff --git a/src/Core/src/Handlers/Window/WindowHandler.Tizen.cs b/src/Core/src/Handlers/Window/WindowHandler.Tizen.cs index 5818d64edb79..eb799888c3cb 100644 --- a/src/Core/src/Handlers/Window/WindowHandler.Tizen.cs +++ b/src/Core/src/Handlers/Window/WindowHandler.Tizen.cs @@ -15,8 +15,7 @@ public static void MapContent(IWindowHandler handler, IWindow window) handler.MauiContext.GetPlatformWindow().SetContent(platformContent); - if (window.VisualDiagnosticsOverlay != null) - window.VisualDiagnosticsOverlay.Initialize(); + window.VisualDiagnosticsOverlay?.Initialize(); } public static void MapX(IWindowHandler handler, IWindow view) => diff --git a/src/Core/src/Platform/Android/MauiScrollView.cs b/src/Core/src/Platform/Android/MauiScrollView.cs index 3be88c06db46..b5e6fbcb26ef 100644 --- a/src/Core/src/Platform/Android/MauiScrollView.cs +++ b/src/Core/src/Platform/Android/MauiScrollView.cs @@ -127,8 +127,7 @@ public void SetOrientation(ScrollOrientation orientation) if (_content != null && _content.Parent != this) { _content.RemoveFromParent(); - if (_hScrollView != null) - _hScrollView.RemoveFromParent(); + _hScrollView?.RemoveFromParent(); AddView(_content); } } diff --git a/src/Core/src/Platform/Android/MauiSearchView.cs b/src/Core/src/Platform/Android/MauiSearchView.cs index 9c8e17f67c47..7c730308ae23 100644 --- a/src/Core/src/Platform/Android/MauiSearchView.cs +++ b/src/Core/src/Platform/Android/MauiSearchView.cs @@ -33,8 +33,7 @@ void Initialize() { var image = FindViewById(searchCloseButtonIdentifier); - if (image != null) - image.SetMinimumWidth((int?)Context?.ToPixels(44) ?? 0); + image?.SetMinimumWidth((int?)Context?.ToPixels(44) ?? 0); } } } diff --git a/src/Core/src/Platform/Android/MauiWebViewClient.cs b/src/Core/src/Platform/Android/MauiWebViewClient.cs index 9598674b85e1..ee6eb9f021e6 100644 --- a/src/Core/src/Platform/Android/MauiWebViewClient.cs +++ b/src/Core/src/Platform/Android/MauiWebViewClient.cs @@ -62,8 +62,7 @@ public override void OnPageFinished(WebView? view, string? url) handler.SyncPlatformCookiesToVirtualView(url); - if (handler != null) - handler.PlatformView.UpdateCanGoBackForward(handler.VirtualView); + handler?.PlatformView.UpdateCanGoBackForward(handler.VirtualView); base.OnPageFinished(view, url); } diff --git a/src/Core/src/Platform/Android/ScrollViewExtensions.cs b/src/Core/src/Platform/Android/ScrollViewExtensions.cs index fffd69a5d382..2e1d5cde8bcc 100644 --- a/src/Core/src/Platform/Android/ScrollViewExtensions.cs +++ b/src/Core/src/Platform/Android/ScrollViewExtensions.cs @@ -33,7 +33,7 @@ internal static void HandleScrollBarVisibilityChange(this IScrollBarView scrollV public static void UpdateContent(this MauiScrollView scrollView, IView? content, IMauiContext context) { - var nativeContent = content == null ? null : content.ToPlatform(context); + var nativeContent = content?.ToPlatform(context); scrollView.RemoveAllViews(); diff --git a/src/Core/src/Platform/Tizen/WrapperView.cs b/src/Core/src/Platform/Tizen/WrapperView.cs index 22e7b340e2b6..3bfcaa3df138 100644 --- a/src/Core/src/Platform/Tizen/WrapperView.cs +++ b/src/Core/src/Platform/Tizen/WrapperView.cs @@ -106,10 +106,7 @@ void UpdateDrawableCanvas(bool geometryUpdate = false) void OnLayout(object? sender, LayoutEventArgs e) { - if (Content != null) - { - Content.UpdateBounds(new TRect(0, 0, Size.Width, Size.Height)); - } + Content?.UpdateBounds(new TRect(0, 0, Size.Width, Size.Height)); if (_clipperView.IsValueCreated) { diff --git a/src/Core/src/Platform/Windows/BorderExtensions.cs b/src/Core/src/Platform/Windows/BorderExtensions.cs index 4129f749eb88..7823a83cd927 100644 --- a/src/Core/src/Platform/Windows/BorderExtensions.cs +++ b/src/Core/src/Platform/Windows/BorderExtensions.cs @@ -60,8 +60,7 @@ public static void UpdateStrokeDashPattern(this Path borderPath, float[]? border if (borderPath == null) return; - if (borderPath.StrokeDashArray != null) - borderPath.StrokeDashArray.Clear(); + borderPath.StrokeDashArray?.Clear(); if (borderDashArray != null && borderDashArray.Length > 0) { diff --git a/src/Core/src/Platform/Windows/ScrollViewerExtensions.cs b/src/Core/src/Platform/Windows/ScrollViewerExtensions.cs index 81350563f0bf..173ce59842c3 100644 --- a/src/Core/src/Platform/Windows/ScrollViewerExtensions.cs +++ b/src/Core/src/Platform/Windows/ScrollViewerExtensions.cs @@ -61,7 +61,7 @@ public static void UpdateScrollBarVisibility(this ScrollViewer scrollViewer, Scr public static void UpdateContent(this ScrollViewer scrollViewer, IView? content, IMauiContext context) { - scrollViewer.Content = content == null ? null : content.ToPlatform(context); + scrollViewer.Content = content?.ToPlatform(context); } } } \ No newline at end of file diff --git a/src/Core/src/Platform/Windows/WindowRootView.cs b/src/Core/src/Platform/Windows/WindowRootView.cs index d8a332d77eb7..f0ee5e37d356 100644 --- a/src/Core/src/Platform/Windows/WindowRootView.cs +++ b/src/Core/src/Platform/Windows/WindowRootView.cs @@ -59,8 +59,7 @@ internal MauiToolbar? Toolbar get => _toolbar; set { - if (_toolbar != null) - _toolbar.SetMenuBar(null); + _toolbar?.SetMenuBar(null); _toolbar = value; if (NavigationViewControl != null) diff --git a/src/Core/src/Platform/iOS/MauiSwipeView.cs b/src/Core/src/Platform/iOS/MauiSwipeView.cs index d45c9106a31a..2ca3ec4331b7 100644 --- a/src/Core/src/Platform/iOS/MauiSwipeView.cs +++ b/src/Core/src/Platform/iOS/MauiSwipeView.cs @@ -708,15 +708,9 @@ void DisposeSwipeItems() _swipeOffset = 0; _originalBounds = CGRect.Empty; - if (_actionView != null) - { - _actionView.RemoveFromSuperview(); - } + _actionView?.RemoveFromSuperview(); - if (_swipeItemsRect != null) - { - _swipeItemsRect.Clear(); - } + _swipeItemsRect?.Clear(); UpdateIsOpen(false); } diff --git a/src/Core/src/Platform/iOS/ScrollViewExtensions.cs b/src/Core/src/Platform/iOS/ScrollViewExtensions.cs index 02c65a3d10e6..47a976c80d61 100644 --- a/src/Core/src/Platform/iOS/ScrollViewExtensions.cs +++ b/src/Core/src/Platform/iOS/ScrollViewExtensions.cs @@ -21,7 +21,7 @@ public static void UpdateHorizontalScrollBarVisibility(this UIScrollView scrollV // TODO ezhart This method is no longer used internally; we can't delete it right now because that'd be a breaking change public static void UpdateContent(this UIScrollView scrollView, IView? content, IMauiContext context) { - var nativeContent = content == null ? null : content.ToPlatform(context); + var nativeContent = content?.ToPlatform(context); if (scrollView.Subviews.Length > 0 && scrollView.Subviews[0] == nativeContent) { diff --git a/src/Core/src/VisualDiagnostics/VisualDiagnosticsOverlay.Android.cs b/src/Core/src/VisualDiagnostics/VisualDiagnosticsOverlay.Android.cs index 1ded8d7839a3..b552dc4d0ca1 100644 --- a/src/Core/src/VisualDiagnostics/VisualDiagnosticsOverlay.Android.cs +++ b/src/Core/src/VisualDiagnostics/VisualDiagnosticsOverlay.Android.cs @@ -67,10 +67,7 @@ static Point GenerateAdornerOffset(View graphicsView) var decorView = nativeActivity.Window?.DecorView; var rectangle = new Android.Graphics.Rect(); - if (decorView is not null) - { - decorView.GetWindowVisibleDisplayFrame(rectangle); - } + decorView?.GetWindowVisibleDisplayFrame(rectangle); float dpi = nativeActivity.Resources.DisplayMetrics.Density; return new Point(0, -(rectangle.Top / dpi)); diff --git a/src/Core/src/WindowOverlay/WindowOverlay.Windows.cs b/src/Core/src/WindowOverlay/WindowOverlay.Windows.cs index b8092f5be588..0d40ba4038c3 100644 --- a/src/Core/src/WindowOverlay/WindowOverlay.Windows.cs +++ b/src/Core/src/WindowOverlay/WindowOverlay.Windows.cs @@ -93,8 +93,7 @@ void DeinitializePlatformDependencies() { _graphicsView.Tapped -= ViewTapped; _graphicsView.PointerMoved -= PointerMoved; - if (_panel != null) - _panel.RemoveOverlay(_graphicsView); + _panel?.RemoveOverlay(_graphicsView); _graphicsView = null; } IsPlatformViewInitialized = false; diff --git a/src/Essentials/src/FilePicker/FilePicker.ios.cs b/src/Essentials/src/FilePicker/FilePicker.ios.cs index de62bc6d16e3..21b4435821f5 100644 --- a/src/Essentials/src/FilePicker/FilePicker.ios.cs +++ b/src/Essentials/src/FilePicker/FilePicker.ios.cs @@ -66,11 +66,11 @@ async Task> PlatformPickAsync(PickOptions options, bool } #if !MACCATALYST - if (documentPicker.PresentationController != null && !(OperatingSystem.IsIOSVersionAtLeast(14, 0) && NSProcessInfo.ProcessInfo.IsiOSApplicationOnMac)) - { - documentPicker.PresentationController.Delegate = - new UIPresentationControllerDelegate(() => GetFileResults(null, tcs)); - } + if (documentPicker.PresentationController != null && !(OperatingSystem.IsIOSVersionAtLeast(14, 0) && NSProcessInfo.ProcessInfo.IsiOSApplicationOnMac)) + { + documentPicker.PresentationController.Delegate = + new UIPresentationControllerDelegate(() => GetFileResults(null, tcs)); + } #endif var parentController = WindowStateManager.Default.GetCurrentUIViewController(true); diff --git a/src/Essentials/test/DeviceTests/Tests/Geocoding_Tests.cs b/src/Essentials/test/DeviceTests/Tests/Geocoding_Tests.cs index 0b6c231d2e28..1db2b723c098 100644 --- a/src/Essentials/test/DeviceTests/Tests/Geocoding_Tests.cs +++ b/src/Essentials/test/DeviceTests/Tests/Geocoding_Tests.cs @@ -16,8 +16,8 @@ public Geocoding_Tests() #endif } -// Temporarily disabling this test on Windows due to consistent CI failures. -// See https://github.com/dotnet/maui/issues/30507 for tracking re-enablement. + // Temporarily disabling this test on Windows due to consistent CI failures. + // See https://github.com/dotnet/maui/issues/30507 for tracking re-enablement. #if !ANDROID && !WINDOWS [Theory] [InlineData(47.673988, -122.121513)] diff --git a/src/Graphics/samples/GraphicsTester.Portable/Scenarios/TestPattern2.cs b/src/Graphics/samples/GraphicsTester.Portable/Scenarios/TestPattern2.cs index 61449720163f..ec36b938e9b9 100644 --- a/src/Graphics/samples/GraphicsTester.Portable/Scenarios/TestPattern2.cs +++ b/src/Graphics/samples/GraphicsTester.Portable/Scenarios/TestPattern2.cs @@ -23,8 +23,7 @@ public override void Draw(ICanvas canvas) canvas.RestoreState(); canvas.SaveState(); - if (blurrableCanvas != null) - blurrableCanvas.SetBlur(5); + blurrableCanvas?.SetBlur(5); canvas.Translate(0, 200); DrawStrokes(canvas); canvas.RestoreState(); @@ -45,8 +44,7 @@ public override void Draw(ICanvas canvas) canvas.RestoreState(); canvas.SaveState(); - if (blurrableCanvas != null) - blurrableCanvas.SetBlur(5); + blurrableCanvas?.SetBlur(5); canvas.Translate(0, 500); DrawFills(canvas); canvas.RestoreState(); diff --git a/src/TestUtils/src/DeviceTests.Runners/VisualRunner/Utils/AsyncLock.cs b/src/TestUtils/src/DeviceTests.Runners/VisualRunner/Utils/AsyncLock.cs index 227fcd6626f2..7286fb2a090b 100644 --- a/src/TestUtils/src/DeviceTests.Runners/VisualRunner/Utils/AsyncLock.cs +++ b/src/TestUtils/src/DeviceTests.Runners/VisualRunner/Utils/AsyncLock.cs @@ -28,8 +28,7 @@ internal Releaser(AsyncLock toRelease) public void Dispose() { - if (toRelease != null) - toRelease.semaphore.Release(); + toRelease?.semaphore.Release(); } }